Friday, March 4, 2011

User-Defined Functions

Write a function exchange to interchange the values of two variables, say x and y. Illustrate the use of this function, in a calling function. Assume that x and y are defined as global variables.

#include <stdio.h>
void exchange(int x,int y);
int x,y;
void main()
{
printf("Enter the value of X:");
scanf("%d",&x);
printf("Enter the value of Y:");
scanf("%d",&y);
exchange(x,y);
getch();
}
void exchange(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("X=%d\nY=%d",x,y);
}

OUTPUT
Enter the value of X : 5
Enter the value of Y : 7
X = 7
Y = 5

No comments:

Post a Comment