Exercise 2
Implement the swap function to exchange the contents of the two
variables using pointer notation for parameter passing.
#include<stdio.h>
void header()
{
printf("\n\n\n\t\tBuilt & Designed by Arslan Malik\n\n\t\t www.CWorldbyAS.blogspot.com\n\n\n");
}
void swap(int *a,int *b)
{
int hold;
hold=*a;
*a=*b;
*b=hold;
}
int main()
{
int x,y;
header();
printf("\n\n\n\n\n");
system("pause");
system("cls");
while(x!=-1)
{
printf("\nEnter Value of X : ");
scanf("%d",&x);
printf("\n\nEnter Value of Y : ");
scanf("%d",&y);
printf("\n\n\n\t\t\t\tBEFORE SWAPPING\n\n\n");
printf("\t\t\t\tX = %d & Y = %d",x,y);
printf("\n\n\n\t\t\t\tAFTER SWAPPING\n\n\n");
swap(&x,&y);
printf("\t\t\t\tX = %d & Y = %d",x,y);
printf("\n\n\n\n");
}
return 0;
}
brother kmal hi kar dia
ReplyDelete