Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Write a c program to swap two numbers without using third variable ?

 Write a c program to swap two numbers without using a third variable?  
 #include<stdio.h>  
 #include<conio.h>  
 int main()   
 {  
   int x, y;  
   printf("\nEnter value for num1 & num2 : ");  
   scanf("%d %d", &x, &y);  
   x = x + y;  
   y = x - x;  
   x = x - y;  
   printf("\nAfter swapping value of a : %d", x);  
   printf("\nAfter swapping value of b : %d", y);  
   return (0);  
 }  
 Output  
 Enter value for num1 & num2 : 20 10  
 After swapping value of a: 10  
 After swapping value of b: 20 

 

Post a Comment

0 Comments