PROGRAM: Write a C program to swap two numbers using 3rd variable.
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d
and b is %d before swaping\n",a,b);
c=a;
a=b;
b=c;
printf("The values of a is %d
and b is %d after swaping\n",a,b);
main()
{
int a,b,c;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d
and b is %d before swaping\n",a,b);
c=a;
a=b;
b=c;
printf("The values of a is %d
and b is %d after swaping\n",a,b);
}
OUTPUT:-
Enter a
35
Enter b
30
The values of a is 35 and b is 30 before swaping
The values of a is 30 and b is 35 after swaping
35
Enter b
30
The values of a is 35 and b is 30 before swaping
The values of a is 30 and b is 35 after swaping
0 Comments