8.28.2011

Simple Swapping C Program

Q. Write a simple program to insert two values through keyboard and interchange then values?
Example:if x=10
           y=20
        then after interchange
          x=20
          y=10
       
Ans.

#include<stdio.h>
#include<conio.h>
int main()
{
 int x,y,z;
 printf("Enter Values x and y : ");
 scnaf("%d%d",&x,&y);
 z=y;
 y=x;
 x=z;
 printf("\nValue of x=%d",x);
 printf("\nValue of y=%d",y);
 getch();
 return 0;
}

        Output of above program : 
Enter Values x and y : 25
35
Value of x= 35
Value of y= 25

No comments:

Post a Comment

Post a Comment