Write a program to input two number from the user and then swap the value of
these two variables by using third variable.
Here swap
simply means interchanging the given data with each other by using third
variable.
In the given
program I’m going to input data in two variables and with the help of third
variable I’m going to swap the data between two.
Let’s go
through program.
#include<stdio.h>
void main();
{
int a, b, c;
clrscr ();
printf (“\n enter the first number”);
scanf (“%d”, &a);
printf (“\n enter the second number”);
scanf (“%d”, &b);
c=b ;
b=a ;
a=c ;
printf (“\n a=%d”, a );
printf (“\n b=%d”, b);
getch ();
}
WORKING AND OUTPUT: -
Here c=b
means those value which were inputted on ‘b’ will transfer to c and then b=a
will helps in transfer of data 0f ‘a’ to ‘b’. And at last through a=c those
value of ‘b’ which were transferred to ‘c’ will now transfer to ‘a’. Through
this ‘a’ and ‘b’ will interchange and displays output as follows;
Enter the first number =
Enter the second number=
a=
b=
Comments
Post a Comment