Sponsors

This is really a easy code for swapping values of variables.Try to understand the logic. We have to take another extra integer (temp).

Logic : Stored the value of “b” in “temp”. Then stored the value of “a” in “b”.Then “c” in “a”.
Finally takeback the value of “b” from “temp” in “c”.

 

Here is the Code:
int a,b,c,temp;

printf(“Enter Value of A, B and C Respectively Using Space : “);
scanf(“%d%d%d”,&a,&b,&c);

temp=b;
b=a;
a=c;
c=temp;

printf(“Value After Swapping Numbers :\n”);
printf(” A= %d \n B= %d \n C= %d \n “,a,b,c);

Sponsors

LEAVE A REPLY

Please enter your comment!
Please enter your name here