yashuop
SOURCE CODE: (using third variable)
#include<stdio.h>
#include<conio.h>void main ()
{ int a,b;
clrscr();
printf("\n\nEnter two numbers : \n");
scanf("%d%d",&a,&b);
printf("Before swapping......\n");
printf("a= %d\n",a);
printf("b= %d\n",b);
a=a+b;
b=a-b;
a=a-b;
printf("After swapping......\n");
printf("a= %d\n",a);
printf("b= %d\n",b);
getch();
} AGORITHM: (without using third variable)
SOURCE CODE: (without using third variable)
#include<stdio.h> #include<conio.h> void main () { int a,b; clrscr(); printf("\n\nEnter two numbers : \n"); scanf("%d%d",&a,&b); printf("Before swapping......\n"); printf("a= %d\n",a); printf("b= %d\n",b); a=a+b; b=a-b; a=a-b; printf("After swapping......\n"); printf("a= %d\n",a); printf("b= %d\n",b); getch(); }
explorer