#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("\n enter two number");
scanf("%d%d",&a,&b);
BEST LOGIC:-
b=(a+b)-(a=b); //let a=10,b=20;
//b=(10+20)-(a=20) //now a become 20
//b=30-20
//finally b=10
AVARAGE LOGIC
a=a+b; //let a=10,20; then a=10+20=30
b=a-b; //b=a-b=30-20=10;
a=a-b; //a=a-b=30-10=20;
printf("after swaping value of a=%d \n",a);
printf("after swaping value of b=%d \n",b);
getch();
}
use any one but 1 is best..
#include<conio.h>
void main()
{
int a,b;
printf("\n enter two number");
scanf("%d%d",&a,&b);
BEST LOGIC:-
b=(a+b)-(a=b); //let a=10,b=20;
//b=(10+20)-(a=20) //now a become 20
//b=30-20
//finally b=10
AVARAGE LOGIC
a=a+b; //let a=10,20; then a=10+20=30
b=a-b; //b=a-b=30-20=10;
a=a-b; //a=a-b=30-10=20;
printf("after swaping value of a=%d \n",a);
printf("after swaping value of b=%d \n",b);
getch();
}
use any one but 1 is best..
No comments:
Post a Comment