Monday, January 31, 2011

Functions in C++

Hi guys!the program below swaps the two values entered by user and passing to a function by value.

If this program give errors please let me know,i am ready to help any time..
May this program helps you alot!!


 
#include<iostream>
#include<conio.h>
using namespace std;
int swap(int a,int b)
{
    int c;
    c=a;
    a=b;
    b=c;
    return a;
    return b;
}
main()
{
int num1,num2,x;
cout<<"enter the first number:";
cin>>num1;
cout<<"enter second number:";
cin>>num2;
x=swap(num1,num2);
cout<<"first number is"<<num1<<"& second number is"<<num2<<",now the numbers are interchanged,first number is"<<x<<"and you have entered"<< num1;
getch();
}

No comments:

Post a Comment