Pages

Friday, July 19, 2013

Write a program that Sample Program with Subfunction in C++

This program demonstrates funtion calls by calling a small funtion to multiply two numbers

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
27
      #include <iostream>
      using namespace std;
      #include <conio.h>
      // Prototype Declarations
      int multiply (int num1, int num2);
      
      int main ()
      {
          int multiplier;
          int multiplicand;
       cout << " Enter two integers: \n";   
       cin  >> multiplier >> multiplicand;
          int Product = multiply (multiplier, multiplicand);
       cout << " Product of " <<  multiplier << " & " << multiplicand
       << " is " << Product ;
       getch();
       return 0;
                } // main
       /* ============ Multiply ==============
       Multiply two numbers and return product.
          pre num1 & num2 contains values to be multiplied
          post product retured            */
       
       int multiply (int num1, int num2)
       {
           return (num1 * num2);
                                }//multiply     

OutPut:

Enter two integers: 17  21
Product of 17 & 21 is 357



No comments:

Post a Comment