Make an algorithm which calculates the sum of n numbers using the cycle:

a) for{}

b) while{}

d0 while{}.

No registration required to write.

2 posts
• Page **1** of **1**

- Code: Select all
`C++:`

int sum = 0;

for (int i = 1; i <= n; ++i)

sum += i;

I hope someone else will try the others.

Let me generalize the algorithm. Try to do it in as many languages as you can.

2 posts
• Page **1** of **1**

Return to Programming and Algorithms

Users browsing this forum: No registered users and 1 guest