38.1k views
5 votes
Write a program that computes the sum of the first tenpositive integers, 1 + 2 + ..+ 10.

User Gold
by
7.4k points

1 Answer

3 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

int sum=0;//taking an integer variable to store the sum with initial value 0..

for(int i=1;i<=10;i++)//looping from 1 to 10..

{

sum+=i;//adding each i in the sum..

}

cout<<sum<<endl;//printing the sum..

return 0;

}

Step-by-step explanation:

output :- 55

1.I have taken an integer variable sum which is equal to 0.

2.Looping over first ten positive integers.

3.Adding every number to sum.

4.Printing the sum.

User Pedrohreis
by
7.3k points

No related questions found