Monday, June 25, 2018

Program to swap two integer values using pointer - DS (C Program)

#include<stdio.h>
void swap(int*,int*);
void main()
{
int a,b;
clrscr();
printf("Enter value of A:");
scanf("%d",&a);
printf("\nEnter value of B:");
scanf("%d",&b);
printf("\nBefore swap,A:%d\n",a);
printf("Before swap,B: %d\n\n",b);
swap(&a,&b);

printf("After swap,A:%d\n",a);
printf("After swap,B: %d\n",b);
getch();
}
void swap(int *x,int *y)
{
int temp=*x;
*x=*y;
*y=temp;
}

No comments:

Post a Comment