Tuesday 21 July 2020

5.12 (Calculating the Product of Odd Integers) Write an application that calculates the product of the odd integers from 1 to 15.

5.12 (Calculating the Product of Odd Integers) Write an application that calculates the product of the odd integers from 1 to 15.

Code:
#include < iostream>
 
using namespace std;
 
int main()
{
  int result = 1;
 
  for( int i = 1; i <= 15; i++ )
  {
     if( i%2 == 1)
       result *= i;
   }
 
  cout << "result is " << result << endl;
 
   //for pause
   system("PAUSE");
   return 0;
}

No comments:

Post a Comment