#include /* computes the sum 1*(0*0) + 4*(1*1) + 2*(2*2) + 4*(3*3) + 2*(4*4) + ... + 2*(num-2)*(num-2) + 4*(num-1)*(num-1) + 1*(num*num), where num is a positive even integer. (This sort of sum comes up in Simpson's rule in calculus.) If i is a counter variable going from 0 to num, then the general term in the sum is of the form coeff*i*i, where the coefficient coeff is determined by this rule: if i is odd, then coeff = 4 if i is 0 or i is num, then coeff = 1 if i is even, and not 0 or num, then coeff = 2 */ void main() { int num=10, sum=0, i, coeff; for (i=0; i<=num; i++){ if (i%2) coeff = 4; else if (i==0 || i==num) coeff = 1; else coeff = 2; sum += coeff * i*i; } cout << "The sum is "<< sum <<".\n"; }