program to swap three number by using pointer in c-programming:
In this program, we will now takes three number from the user and swap this three number by using pointer.
#include<stdio.h>
#include<conio.h>
int fun(int *,int *,int *);
void main()
{
int x,y,z;
printf("enter the three number:-");
scanf("%d %d %d",&x,&y,&z);
printf("\n before swapping:x=%d y=%d and z=%d",x,y,z);
fun(&x,&y,&z);
printf("\n after swapping: x=%d y=%d and z=%d",x,y,z);
getch();
}
int fun(int *a,int *b,int *c)
{
int i;
i=*b;
*b=*a;
*a=*c;
*c=i;
}
#include<conio.h>
int fun(int *,int *,int *);
void main()
{
int x,y,z;
printf("enter the three number:-");
scanf("%d %d %d",&x,&y,&z);
printf("\n before swapping:x=%d y=%d and z=%d",x,y,z);
fun(&x,&y,&z);
printf("\n after swapping: x=%d y=%d and z=%d",x,y,z);
getch();
}
int fun(int *a,int *b,int *c)
{
int i;
i=*b;
*b=*a;
*a=*c;
*c=i;
}
output:-

No comments:
Post a Comment