471,850 Members | 1,062 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,850 software developers and data experts.

Body of For loop

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 7861
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>
  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

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 NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.