Computer Science, asked by mahesss30, 1 month ago

Write a program for swap two numbers without using 3rd variable?

Answers

Answered by mahesijjh
1

//In c language , I wrote this program!

#include <stdio.h>

void main()

{

int a,b; 

printf("enter number1: ie a");

scanf("%d",&a); 

printf("enter number2:ie b ");

scanf("%d",&b); 

printf(value of a and b before swapping  is a=%d,b=%d"a,b); 

a=a+b; 

b=a-b; 

a=a-b; 

printf("value of a and b after swapping  is a=%d,b=%d"a,b); 

}

 OUTPUT :

 

 enter number1: ie a 12

 enter number2: ie b 23

 

 value of a and b before swapping  is a=12,b=23

 value of a and b after swapping  is a=23,b=12

Similar questions