Need Help on this
Write a program that calculates and print the product of the odd integer s from 1 to 15.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
using namespace std;
int main()
{
int integer;
int product;
product = 1;
for (integer = 1; integer <= 15; integer++)
{
if (integer % 2 != 0)
product = integer * integer;
}
cout << " The Product = " << product<<endl;
system("pause");
return 0;
}
|
the answer i get is 225 , but the answer should be 10395
Your line 13 overwrites the value of product. It should modify.
Topic archived. No new replies allowed.