Program statement: Two numbers are input through the keyboard into two locations C and D. write a program to interchange the contents of C and D without using temporary variable.
source file name: swap1.C
void main()
{
int C,D;
clrscr();
printf("Interchange of two variables program");
printf("\n enter 2 numbers C and D");
scanf("%d%d",&C,&D);
C=C+D;
D=C-D;
C=C-D;
printf("\n after interchange values are C=%d and D=%d", C,D);
getch();
}
Output:
1. Interchange of two variables program
enter 2 numbers C and D
100 200
after interchange values are C=200 and D=100
2. Interchange of two variables program
enter 2 numbers C and D
25 -20
after interchange values are C= -20 and D=25
0 Comments
Post a Comment