Home
»
» Unlabelled
» Arguments Passed By Reference in C++
Write a function called zero_small() that has two integer arguments being passed by reference and sets the smaller of the two numbers to 0. Write the main program to access the function.
Source Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| #include<iostream>
using namespace std;
void zero_small(int &,int &);
int main()
{
int x,y;
cout<<"Enter first number : ";
cin>>x;
cout<<"Enter second number : ";
cin>>y;
zero_small(x,y);
cout<<"First number is : "<<x;
cout<<"\nSecond number is : "<<y;
return 0;
}
void zero_small(int &a, int &b)
{
if(a<b)
a=0;
else
b=0;
}
|
SAMPLE RUN # 1
Enter first number : 23
Enter second number : 6
First number is : 23
Second number is : 0
SAMPLE RUN # 2
Enter first number : 23
Enter second number : 56
First number is : 0
Second number is : 56
Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.