hi
i start to learn c++. there is a lab asking
write a program to add between 1 to 20 using a for loop. Check that the program
ontained the right answer by using the formula for sum of the number 1 to n:
n(n+1)/2
i know its very easy but if you know!!!
can any body help me????
You can use an accumulator in a for loop like this
# include <iostream.h>
void main()
{
clrscr();
int ctr, sum=0; // Defining counter and accumulator
for (ctr=1;ctr<=20;ctr++)
{ sum++;
}
Does this help??
}