Sunday, 1 September 2013

Swapping Program With function

Posted by Unknown On 10:24 | No comments

/* Program to SWAP two variable without using THIRD variable in C++ (with function) */ 

/*In this program will will not use third variable to swap the the variable but we will be using the operator to do so. Here we will be using a swap function to swap the value but it will be done by using call by reference.*/

/* Program to swap the value without using the third variable*/

//Header File
#include<iostream.h>
void swap(int &a,int &b);
int main()
{
int a,b;
cout<<"\n Enter First No:- ";
cin>>a;
cout<<"\n Enter Second No:- ";
cin>>b;

cout<<"\n Value before swaping. a= "<<a<<" b="<<b;
swap(a,b);
cout<<"\n Value after swaping. a= "<<a<<" b="<<b;
return 0;
}
void swap(int &a,int &b) //CALL BY REFERNCE
{
a=a+b;
b=a-b;
a=a-b;
}

0 comments:

Post a Comment

Blogroll

Copyright © 2013 RAJ PRAJAPATI (raj@electronicsrj.com)

Comments

About Projects

We also Provide support in making Electronics Projects at different level at Cheapest price. Contact Us for the further help.