hello

header ads

Function program

 #include <iostream>

using namespace std;

// function declaration or prototyping

int max(int, int);

int main () {

   // local variable declaration:

   int a = 300;

   int b = 200;

   int ans;

  // calling a function to get max value.

   ans = max(a, b);

   cout << "Max value is : " << ans << endl;

   return 0;

// function definition or declaration

int max(int num1, int num2) {

   // local variable declaration

   int result;

   if (num1 > num2)

      result = num1;

   else

      result = num2;

 

   return result; 

}




Program 2

#include <iostream>

using namespace std;

// function declaration or prototyping

int max(int, int);

int main () {

   // local variable declaration:

   int num1 = 110;

   int num2 = 200;

   int ans;

   // calling a function to get max value.

   ans = max(num1, num2);

   cout << "Max value is : " << ans << endl;

   return 0;

}

 

// function definition or declaration

int max(int num1, int num2) {

   // local variable declaration

   int ans;

 

   if (num1 > num2)

      ans = num1;

   else

      ans = num2;

 

   return ans; 

}

Post a Comment

0 Comments