Tuesday, 17 March 2015

C program to Swapping of two numbers without using third variable

#include <stdio.h>
 
int main()
{
   int a, b;
 
   printf("Enter two integers to swap\n");
   scanf("%d%d", &a, &b);
 
   a = a + b;
   b = a - b;
   a = a - b;
 
   printf("a = %d\nb = %d\n",a,b);
   return 0;
}
 
Output Of Program: 

Enter two integers to swap
10
20 

a=20
b=10

No comments:

Post a Comment