loop code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kpdp
    New Member
    • Nov 2008
    • 7

    loop code

    hey,
    i know that this is a really easy question...but i can't seem to figure out what's wrong with the code.. this function is meant to state every odd number.

    #include<stdio. h>

    int main (void)
    {
    int i, sum=0;
    for (i=1; i<=21; i=i+2) {
    (sum = sum + 1);

    printf("%d\n",s um );
    }
    return 0;

    }
  • kpdp
    New Member
    • Nov 2008
    • 7

    #2
    nevermind...
    it's

    #include<stdio. h>

    int main (void)
    {
    int i, sum=0;
    for (i=1; i<=21; i=i+2) {
    (sum = sum + i);

    printf("%d\n", i);
    }
    return 0;

    }

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      odd integer for loop

      In sum=sum+1...... ..... try replacing 1 with i

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Actually try removing the variable sum altogether it makes no contribution to the program

        Comment

        Working...