It says write a program. It doesn't say what language to use, right?
If you wanted to print the addition of numbers 1 through 10, could you do that?
using 'bash' script as an example:
1 2 3 4 5
|
declare -i i sum=0 n=10
for ((i=1; i<=n; ++i)); do
sum=$sum+$i
done
printf "sum is %d\n" "$sum"
|
Now the divide by 3, that's done for everything, so do it
outside of the loop.
You also want to toss in n
2, so in the above loop you would calculate "$i*$i" and add it to sum as well... preferably in the same line like
sum=$sum+$i+$i*$i
For the final answer, after the done and before you print, divide '$sum' by 3:
sum=$sum/3
Now since you are posting this in a C++ forum, you likely want a c++ answer, but certainly you wouldn't want me to give you that much help. But the above is *how* you would do it. As for what language you do it in, that's between you and your teacher... ;-)
The above will work in a 'bash' "shell" on linux or in "cygwin" on windows. and will give an 'integer' answer (bash doesn't do floats or doubles), but hopefully that should give you an idea...? ;-)