click on this link......

LinkGrand.com
Showing posts with label swapping of two numbers. Show all posts
Showing posts with label swapping of two numbers. Show all posts

Thursday, 12 September 2013

Swapping of two numbers using call by reference

#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
int a,b;
clrscr();
printf("\nEnter two nos: ");
scanf("%d%d",&a,&b);
printf("\nvalues before swapping: %d\t%d",a,b);
swap(&a,&b);
printf("\nvalues after swapping: %d\t%d",a,b);
getch();
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

Output:
Enter two nos: 25 62
values before swapping: 25      62
values after swapping: 62    25

Swapping of two numbers using call by value

#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a,b;
clrscr();
printf("\nEnter two nos: ");
scanf("%d%d",&a,&b);
printf("\nvalues before swapping: %d\t%d",a,b);
swap(a,b);
getch();
}
void swap(int x,int y)
{
int t;
t=x;
x=y;
y=t;
printf("\n values after swapping: %d\t%d",x,y);
}

Output :
Enter two nos: 5 6
values before swapping:  5      6
values after swapping: 6      5