Saturday, July 20, 2013

Swap two values without 3rd variable in C

Swap the values of two variables without using third variable

#include<stdio.h>
int main()
{
 int a,b;
 printf("Type value of A : ");
 scanf("%d",&a);
 printf("\nType value of B : ");
 scanf("%d",&b);
  a = a + b;
  b = a - b;
  a = a - b ;

 printf("A : %d",a);
 printf("\nB : %d",b);
 }

No comments:

Post a Comment