Body of For loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jvzj017
    New Member
    • Oct 2006
    • 10

    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.
  • koder
    New Member
    • Sep 2006
    • 23

    #2
    sorry,i could not get your question correctly,if some got a better code please let me know

    Code:
    #include<stdio.h>
    
    main()
     {
       long i;
       long result=1;
       for(i=10;i<20;)
        {
            if((i%2))
             {
            result=result*i;
             i++;
             }
            i++;
        }
     printf("\n %d",result);
    }
    thanks a lot and sorry for the whole code posting

    Comment

    • rawinder dhillon
      New Member
      • Oct 2006
      • 8

      #3
      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 ;
      }

      Comment

      Working...