Tuesday, February 9, 2016

Changing(swapping) value of two variables without use of third variable.

#include<stdio.h>
int main()
{
int n1,n2;
printf("Enter n1:");
scanf("%d",&n1);
printf("Enter n2:");
scanf("%d",&n2);

n1=n1+n2;
n2=n1-n2;
n1=n1-n2;
printf("n1=%d \n",n1);
printf("n2=%d",n2);
return 0;
}
/*Output
Enter n1:10
Enter n2:20
n1=20
n2=10
*/




You may also like to learn following programs:

No comments:

Post a Comment