Here is the code of the program.

 

#include <iostream.h>

 

main()

{

    //declaration of variables

    int factorial, number;

   

    //Initialization of the variables

    factorial = 1;

    number = 1;

   

    // Prompt the user to enter upper limit of integers

    cout << “Please enter the number for factorial ” ;

    cin  >> number;

 

    // using the while loop to find out the factorial

   

    while(number > 1)

    {

        factorial = factorial * number;        

        number = number - 1;

    }

   

    cout << "The factorial is  “ << factorial;

}

 

 

The output of the program is as follows:

 

Exercise

1)       Calculate the sum of odd integers for a given upper limit.  Also draw flow chart of the program.

2)       Calculate the sum of even and odd integers separately for a given upper limit using only one loop structure. Also draw flow chart of the program.

 

 

Previous

 

TOC

 

Next