SWAPPING OF TWO NUMBERS USING POINTERS - C-Tutorial

Latest

Monday, 26 September 2016

SWAPPING OF TWO NUMBERS USING POINTERS

/* SWAPPING OF TWO NUMBERS USING POINTERS */

#include<stdio.h>
#include<conio.h>

void swap(int *,int *);
main()
{
int x,y;
clrscr();
printf("\n Enter x,y values: ");
scanf("%d%d",&x,&y);
printf("\n Before swapping X=%d, Y=%d",x,y);
swap(&x,&y);
printf("\n After swapping X=%d, Y=%d",x,y);
getch();
}

void swap(int *p,int *q)
{
int temp;

temp=*p;
*p=*q;
*q=temp;
}

No comments:

Post a Comment