loop structure sum help..

Write your question here:

Write a program that calculates the sum of sequence 1 to 5.
(Using LOOP STATEMENT)

please help.. I've been try it for hours using for-statement.
All I could do was just to create the sequence of 1 to 5..

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
for(int a=1;a<=5;a++)
{
cout<<a;
}
getch();
return 0;
}
you need a variable declared OUTSIDE your for loop ('sum' for example, and initiliase to zero).

then in your for loop just add 'a' to this variable, and reassign back into sum.
Last edited on
Topic archived. No new replies allowed.