Program to swap two numbers

Swapping means interchanging values of a and b, i.e, value of a in b and b in a.

# include<stdio.h>
void main()
{
int a, b, c;
printf("Enter values in a and b:");
scanf("%d%d",&a, &b);
c=a;
a=b;
b=c;
printf("a= %d\nb= %d",a,b);
}

EXPLANATION:-
a=10,b=20
c=a, value of a is assigned to c. So, c=10
a=b, value of b is assigned to a. So, a=20  
b=c, value of c is assigned to b. So, b=10
hence, a=20, b=10(Value assigned) 

Post a Comment

0 Comments