English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

hey couldnt go over 1000 words, i have 2 more questions............
3:Assume the int variables i and result , have been declared but not initialized. Write a for loop header -- i.e. something of the form
for ( . . . )
for the following loop body:

result = result * i;
When the loop terminates, result should hold the product of the odd numbers between 10 and 20.
NOTE: just write the for loop header; do not write the loop body itself. .................................

4:Assume the int variables i , lo , hi , and result have been declared and that lo and hi have been initialized.

Write a for loop that adds the integers between lo and hi (inclusive), and stores the result in result .

Your code should not change the values of lo and hi . Also, do not declare any additional variables -- use only i , lo , hi , and result .

2007-02-15 14:33:49 · 5 answers · asked by Alex P 2 in Computers & Internet Programming & Design

5 answers

I consider helping to be helping you to understand, not doing it for you, so that's why I'm writing it like so...

#3
for (i=whateverItStartsAs, result=whateverThatStartsAs; i < 20; i = i + whatever)
{
// Body of loop
}

In other words, you figure out how to get the product of the odd numbers, but that's how you would construct the header, and into that you have to figure out where you want them to start, and how you want i to increment (or decrement, or change, whatever).

#4
You will want to set result to 0, and then run a loop taking i from lo to hi inclusive (inclusive means <= ) and add each number (i) to result.

2007-02-15 14:47:15 · answer #1 · answered by T J 6 · 0 1

3.

for(i = 10; result < 20; i++) // not sure on this; the question is a bit unclear

4.

for(i = lo; i <= hi; i++) {
result += i;
}

2007-02-15 14:52:51 · answer #2 · answered by Anonymous · 0 0

I have answered u r question before...
U asked it twice..
Here it is:

3.


for(i=11,result=0;i<=20;i+=2)
{
result*=i;
}

4.

for(i=lo+1,result=0;i {
result+=i;
}

Anyways if it is correct then choose me here too

OM NAMAH SHIVAY

2007-02-16 03:58:52 · answer #3 · answered by Gurudev 3 · 0 0

for(i=11,result=1;i<=20;i+=2)

2015-10-14 12:42:04 · answer #4 · answered by Grin 1 · 0 0

4.

for(int i = lo; i < hi; ++i)
{
result += i;
}

piece of cake.

2007-02-15 15:12:10 · answer #5 · answered by rwtire2002 2 · 0 3

fedest.com, questions and answers