Program to swap two numbers with address and pointers. Again, a necessary program for all amateur CSE students.
#include<stdio.h>
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
void main()
{
int a,b;
printf("Enter the number a:");
scanf("%d",&a);
printf("\n Enter the number b:");
scanf("%d",&b);
swap(&a,&b);
printf("\n a contain %d",a);
printf("\n b contain %d",b);
}
#include<stdio.h>
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
void main()
{
int a,b;
printf("Enter the number a:");
scanf("%d",&a);
printf("\n Enter the number b:");
scanf("%d",&b);
swap(&a,&b);
printf("\n a contain %d",a);
printf("\n b contain %d",b);
}
No comments:
Post a Comment