Today we are learn how to swap (exchange 1st number with 2number) two number useing third variable , this is very simple and easy to understand
We are take the input from user using “scanf” function .we are simply take temporary third variable and put equal to first variable and first variable equal to second variable similarly second variable equal to third variable.
this is look like:
tem = a
a = b
b = tem
Now I hope so now you can understand that is logic to swap to number using third variable.
let go througth solution for better understanding.
SOURCE CODE:
#include<stdio.h>
int main(){
int a,b,c;
printf("Swap the two number\n");
printf("Enter the value of a=");
scanf("%d",&a);
printf("Enter the value of b=");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("a=%d,b=%d",a,b);
return 0;
}
0 Comments