C Program to swap Two numbers using Pointers
#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
int main()
{
int a,b;
printf("Enter Two number: ");
scanf("%d%d",&a,&b);
printf("\nBefore Swap a:%d b:%d\n",a,b);
swap(&a,&b);
printf("\nAfter Swap a:%d b:%d\n\n",a,b);
getch();
}
void swap(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
int main()
{
int a,b;
printf("Enter Two number: ");
scanf("%d%d",&a,&b);
printf("\nBefore Swap a:%d b:%d\n",a,b);
swap(&a,&b);
printf("\nAfter Swap a:%d b:%d\n\n",a,b);
getch();
}
void swap(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
OUTPUT:

0 Comments