/* Swapping using 3rd variable */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf(" after swapping a,b %d %d",a,b);
getche();
}
/* Swapping without using 3rd variable */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf(" after swapping a,b %d %d",a,b);
getche();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf(" after swapping a,b %d %d",a,b);
getche();
}
/* Swapping without using 3rd variable */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the values of a,b");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf(" after swapping a,b %d %d",a,b);
getche();
}
No comments:
Post a Comment