Algorithm

Algorithm

Postby kate » Fri Jul 04, 2008 11:26 am

Make an algorithm which calculates the sum of n numbers using the cycle:
a) for{}
b) while{}
d0 while{}.
kate
 
Posts: 90
Joined: Mon Apr 09, 2007 3:58 pm
Reputation: 2

Postby Fed_BG » Tue Aug 26, 2008 1:35 pm

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.

Fed_BG
 
Posts: 17
Joined: Sun Jul 15, 2007 1:22 pm
Location: Bulgaria
Reputation: 0


Return to Programming and Algorithms



Who is online

Users browsing this forum: No registered users and 0 guests

cron