Swap Two Number Using 3rd Variable
Program Code :
int main(){
int a,b,c;
printf("Enter the value of a and b\n");
scanf("%d%d",&a,&b);
printf("Before swap two this number a=%d and b=%d\n",a,b);
c=a+b;
a=c-a;
b=c-b;
printf("Now a=%d and b=%d",a,b);
return 0;
}
Hence , a=10 and b=20 ; Here c=a+b=10+20=30 ; a=c-a=30-10=20 ; b=c-b=30-20=10
Input
Enter the value of a and b
10
20
Output :
Before swap two this number a=10 and b=20
Now a=20 and b=10
No comments:
Post a Comment