Header Ads Widget

Responsive Advertisement

Ticker

10/recent/ticker-posts

C language to swapping between numbers without using third variable.


/*Write a program in c language swapping between numbers without using Third Variable*/
 Or 
/* write a program in c language change between number without using Third Variable */

 Example :- 

Input number 

A= 4 // A is variable 
B = 6 // B is variable

Output – 

/* Swapping number */ 

A = 6 
B = 4 

Understanding algorithms 

B = A + B // 4 + 6 = 10
                                 // Add A variable and B Variable and copy in B Variable. 
A = B – A ; // 10 – 4 = 6 
                                 // Sub B variable and A variable and copy in A Variable. 
B = B – A ; // 10 – 6 = 4 
                               // Sub B variable and A variable and copy in B Variable. 


Let start programming 

# include <stdio.h>
Void main() 

Int a, b; 
Printf(“ Enter the value of A and B “); 
Scanf(“%d\n%d”,&a,&b);                       // input a = 6 and b = 4; 
Printf(“ After swapping \n”); 
/* swapping */ 
b = a + b; 
a = b - a;
 b = b - a; 
printf(“a = %d \n b = %d “, a, b);          //Output = a = 4 and b = 6; 
}

Post a Comment

1 Comments

If you have any doubts about the Programming language & Basic Computer. Please let me know.