Sunday, June 1, 2014

C++ Program to find largest number using function

#include <iostream>
#include <conio.h>
using namespace std;
int max(int , int); // function declaration
int main ()
{
int x; // local variable declaration:
int y;
int ans;
cout<<"Enter the first value:";
cin>>x;
cout<<"Enter the second value:";
cin>>y;
ans = max(x, y); // calling a function to get max value.
cout << "Max value is : " << ans << endl;
getchar();
return 0;
}
int max(int num1, int num2) // function definition
{
int result; // local variable declaration
if (num1 > num2)
result = num1;
else
result = num2;
getchar();
return result;
}



No comments:

Post a Comment