using third variable:
#include<stdio.h> OUTPUT same of both
#include<conio.h> enter two numbers: 4 7
main() a=7 b=4
{
int a,b,t;
printf("enter two numbers");
scanf("%d %d",&a,&b);
t=a;
a=b;
b=t;
printf("a=%d b=%d",a,b);
getch();
}
Without using third variable
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
printf("enter two numbers");
scanf("%d %d ",&a,&b);
a=a+b;
b=a-b;
a=a-b:
printf("a=%d b=%d",a,b);
getch();
}
No comments:
Post a Comment