First Method:
#include <stdio.h>
int main()
{
int a, b, c;
printf("Enter A & B:");
scanf("%d%d", &a, &b);
printf("Before swapping: a = %d, b = %d", a, b);
c=a;
a=b;
b=c;
printf("\nAfter swapping: a = %d, b = %d", a, b);
return 0;
}
Second Method:
#include <stdio.h>
int main()
{
int a, b, c;
printf("Enter A & B:");
scanf("%d%d", &a, &b);
printf("Before swapping: a = %d, b = %d", a, b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping: a = %d, b = %d", a, b);
}
No comments:
Post a Comment