Problem:
Swap the 2 number without using any third variable .
Solution:
#include<conio.h>
#include<stdio.h>
void main()
{
int a, b;
clrscr();
printf("\n enter the two no ");
scanf("%d%d",&a,&b);
printf("before swape \n A=%d B=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nafter swape \n A=%d B=%d",a,b);
getch();
}
Output:
Swap the 2 number without using any third variable .
Solution:
#include<conio.h>
#include<stdio.h>
void main()
{
int a, b;
clrscr();
printf("\n enter the two no ");
scanf("%d%d",&a,&b);
printf("before swape \n A=%d B=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nafter swape \n A=%d B=%d",a,b);
getch();
}
Output:
No comments:
Post a Comment