Ok, variable "n" is set to the value 10.
Ok, you're setting a variable "s" to the value 1.
for (i = 0; i <= n; i++) { |
Guessing you meant to add the missing word "int" before i. Ok, iterating by setting i to values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
if "n" is even , nothing happens. Did you mean "i" ? And your erroneous semicolon ";" is the "nothing happens".
Ok, with each iteration of for loop, set sum to be the product of itself and the
square of i (doesn't matter if i is even or not, since nothing happened there). Not sure why you want to square "i" -- did you mean a normal product? Also, the result of this will be 0 since we start at i=0. Not sure what "sum" is, since you had an "s" earlier.
Uh, what is P? You have "s", "sum", and "P" ? ;D
Hint: helps if you actually provide real code that compiles, preferably with [ code ] ... [ /code ] tags -- you'll spot errors much easier.
Working, compiling example with proper code tags:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
using namespace std;
int main()
{
int n = 10;
int p = 1;
for (int i=2; i<=n; i+=2)
p *= i;
cout << p << endl;
return 0;
}
|