(Under Progress)

Program to find the square of the larger number using a function (Return by reference method)

#include <iostream.h>

int main()
{
 int num1, num2, x;
 int sqlarge( int &, int& );      // Function prototype declared
 cout << "Enter two numbers:\n";
 cin >> num1 >> num2;
 x = sqlarge( num1, num2 );       // Function call

 cout << "\nSquare of the larger number is " << x;
 return 0;
}

int sqlarge( int &n1, int &n2 )   // Function Definition
{
 int sq;
 if ( n1 > n2 )
 sq = n1*n1;
 else
 sq = n2*n2;
 return (sq);
}   

Screenshots:


 
 

Categories