Wednesday, 28 November 2012

Swap using two variables in C program


Write this program and run in Turbo C++ or DEV C++

#include<stdio.h>
#include<conio.h>
void main(){
       int a,b;
       printf("Enter Value of A & B:");
       scanf("%d%d",&a,&b);
       b=a+b;
       a=b-a;
       b=b-a;
       printf("A=%d\tB=%d",a,b);
       getch();
 }

Output:
Enter Value of A & B: 
4   9
A=9            B=4

No comments:

Post a Comment