c Programming

Write a Program to Swap Values of Two Variables using Third Variable

By April 4, 2016 November 9th, 2016 No Comments

/*Program to Swap Values of Two Variables using Third Variable*/
#include <stdio.h>
main()
{
int a, b, temp;
printf(“\nEnter any two numbers: “);
scanf(“%d %d”, &a, &b);
printf(“\n\nBefore Swapping:\n”);
printf(“\na = %d\n”, a);
printf(“\nb = %d\n”, b);
temp = a;
a = b;
b = temp;
printf(“\n\nAfter Swapping:\n”);
printf(“\na = %d\n”, a);
printf(“\nb = %d\n”, b);
getch();
}

Leave a Reply