请看下列程序
#include<stdio.h> //Swap function to swap 2 numbers void swap(int *num1, int *num2) { int temp; //Copy the value of num1 to some temp variable temp = *num1; //Copy the value of num2 to num1 *num1 = *num2; //Copy the value of num1 stored in temp to num2 *num2 = temp; } int main() { int num1, num2; //Inputting 2 numbers from user printf("\nEnter the first number : "); scanf("%d", &num1); printf("\nEnter the Second number : "); scanf("%d", &num2); //Passing the addresses of num1 and num2 swap(&num1, &num2); //Printing the swapped values of num1 and num2 printf("\nFirst number : %d", num1); printf("\nSecond number : %d", num2); return (0); }
结果
C语言教师,计算机科学专业。php 专家
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!