Program 12:
#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); }Explanation:
- Here we initialized a,b,c
- a---> for storing 1st number
- b--->for storing second number
- c---->for storing temporary variable
- Now here goes the logic(let us take a=1 and b=3)
- c=a, Therefore, c=1
- a=b, Therefore a=3
- b=c, Therefore b=1
- Now the values of a and b are 3 and 1
- The values of a and are printed.