468,513 Members | 1,712 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

Body of For loop

10
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.
Oct 11 '06 #1
2 7488
koder
23
sorry,i could not get your question correctly,if some got a better code please let me know

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. main()
  4.  {
  5.    long i;
  6.    long result=1;
  7.    for(i=10;i<20;)
  8.     {
  9.         if((i%2))
  10.          {
  11.         result=result*i;
  12.          i++;
  13.          }
  14.         i++;
  15.     }
  16.  printf("\n %d",result);
  17. }
thanks a lot and sorry for the whole code posting
Oct 11 '06 #2
hi brother

first of all we will ahve to initilize result or declared it as static variable
if we does't do above things then the variable have a garbage value in it and the result will not you want

the loop for

for(i=11;i<20;i=i+2)
{
result=result*i;
}
Oct 11 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by mike | last post: by
8 posts views Thread by localhost | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.