3. Write a program to list all the numbers from 112 to 212 along with the cumulative total. For example:?
sonal p
2008-07-21 14:01:29 UTC
3. Write a program to list all the numbers from 112 to 212 along with the cumulative total. For example:
112 112
113 225
114 339
Five answers:
some_guy
2008-07-21 14:26:18 UTC
Just loop the numbers from 112 to 212 with a variable that keeps adding each number.
In C language :
#include
void main()
{
int i,cumulative=0;
for (i=112;i<=212;i++)
{
cumulative+=i;
printf("%d %d\n",i,cumulative);
}
}
conehead
2008-07-21 14:09:50 UTC
First off, this is your homework. You can get help here, but no one's going to do it for you.
Secondly, you didn't bother to specify the language.
This is a pretty easy program. Declare an int, call it num. Declare another int, call it cumulative, and init it to 0.
loop from num=112 to 212
cumulative = cumulative + num
print out num cumulative
Try to code something and post it. Someone will help you fix your code.
gigahertz205
2008-07-21 14:11:02 UTC
It really depends on the language.
in C#:
public class Numbers
{
public WriteNumbers()
{
int x = 112, y = 0;
while (int i = 112; i <= 212; i++)
{x += y;
y = x;
Console.WriteLine(@"{0} -- {1}, i,x); }
}
}
Passionately Curious
2008-07-22 10:47:40 UTC
You haven't specified a language so I'll do it in Python:
nums = range(112, 213) #213 so that the list contains 212
for i in nums:
....print i, sum(nums[:i-111])
or
num = 112
total = 112
while num <= 212:
....print num, total
....num += 1
....total += num
?
2017-01-05 12:34:05 UTC
you are the appropriate! (an component- of tickles for u). "She spent 20 minutes finding on the orange juice can because of the fact it suggested: "focus..." Blondie exchange into hypnotized. "one hundred% organic" sparkling, orange you? = )
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.