Read OnLine C- Program Example

07_POINTER (02_SWAPING)
PRAC 3 PRAC 4
//wap to print swaping of a two number
#include<stdio.h>
#include<conio.h>
void swap(int a,int b)
{
int c;
clrscr();
printf("\n Before swap a=%d",a);
printf("\n Before swap b=%d",b);
c=a;
a=b;
b=c;
printf("\n After swap a=%d",a);
printf("\n After swap b=%d",b);
}
void main()
{
int x,y;
x=5;
y=6;
swap(x,y);
getch();
}
----------output-----------
Before swap a=5
Before swap b=6
After swap a=6
After swap b=5
//wap to print swaping of a two number
#include<stdio.h>
#include<conio.h>
void swap(int *a,int *b)
{
int c;
clrscr();
printf("\n Before swap a=%d",*a);
printf("\n Before swap b=%d",*b);
c=*a;
*a=*b;
*b=c;
printf("\n After swap a=%d",*a);
printf("\n After swap b=%d",*b);
}
void main()
{
int x,y;
x=5;
y=6;
swap(&x,&y);
getch();
}
-------output-------
Before swap a=5
Before swap b=6
After swap a=6
After swap b=5
Previous Next
Download Download