Friday, October 1, 2010

C program to exchange the values in two variables (swap) with and without using temporary variables.

//to swap the values of variable without using third variable
main()
{
int a,b;
printf("Enter the value of variable a\n");
scanf("%d",&a);
printf("Enter the value of variable b\n");
scanf("%d",&b);
printf("a=%d\nb=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("Swaping done....\n");
printf("Now a=%d\nb=%d\n",a,b);
system("pause");
}

No comments:

Post a Comment

Google+ Followers