Example of C part 6 swapping two number
SWAP USING TEMPORARY VARIABLE
PROGRAM :
Output:
Enter a
35
Enter b
30
The values of a is 35 and b is 30 before swaping
The values of a is 30 and b is 35 after swaping
PROGRAM :
#include<stdio.h> main() { int a,b,c; printf("Enter a\n"); scanf("%d",&a); printf("Enter b\n"); scanf("%d",&b); printf("The values of a is %d and b is %d before swaping\n",a,b); c=a; a=b; b=c; printf("The values of a is %d and b is %d after swaping\n",a,b); }
Enter a
35
Enter b
30
The values of a is 35 and b is 30 before swaping
The values of a is 30 and b is 35 after swaping