Saturday, January 11, 2014

PROGRAM TO SWAP TWO NUMBERS USING POINTERS

#include<stdio.h>
void swap(int *,int *);
main()
{
//swap(int,int);
int a=10,b=20;
printf("Before Swapping:\na=%d\nb=%d\n",a,b);
swap(&a,&b);
}
void swap(int *x,int *y)
{
int z;
z=*x;
*x=*y;
*y=z;
printf("After Swapping:\na=%d\nb=%d\n",*x,*y);
}
~
~
"swapp.c" 17L, 246C                                           16,1          All~
~

OUTPUT:

"swapp.c" 17L, 232C written
[staff@linuxserver staff]$ cc swapp.c
[staff@linuxserver staff]$ ./a.out
Before Swapping:
a=10
b=20
After Swapping:
a=20

b=10

No comments:

Post a Comment