Program to swap two desire integer value , by using pointer and function calling method.
here use of function swap "swap(int *x,int *y)"
which define outside the body of main function .
Source Code:-
#include<iostream.h>
#include<conio.h>
void swap(int *x,int *y);
void main()
{clrscr();
int a,b;
cout<<"\tThe program for Swapping using pointers by-VARUN KUMAR\n";
cout<<"Enter First Value : ";
cin>>a;
cout<<"Enter Second Value: ";
cin>>b;
swap(&a,&b);
cout<<"\nSwapped Values\n";
cout<<"a="<<a<<"and b="<<b<<"\n";
getch();
}
void swap(int *x,int *y)
{int temp;
temp=*x;
*x=*y;
*y=temp;
}
here use of function swap "swap(int *x,int *y)"
which define outside the body of main function .
Source Code:-
#include<iostream.h>
#include<conio.h>
void swap(int *x,int *y);
void main()
{clrscr();
int a,b;
cout<<"\tThe program for Swapping using pointers by-VARUN KUMAR\n";
cout<<"Enter First Value : ";
cin>>a;
cout<<"Enter Second Value: ";
cin>>b;
swap(&a,&b);
cout<<"\nSwapped Values\n";
cout<<"a="<<a<<"and b="<<b<<"\n";
getch();
}
void swap(int *x,int *y)
{int temp;
temp=*x;
*x=*y;
*y=temp;
}
Bro your content helped me lot
ReplyDelete