#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Odd numbers counting


    Help me please! :(
    what's the coding for getting the average of only the odd numbers? I really I'm confuse and I'm still new in this programming.

    Pls help
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    Show us what you've written so far.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    Originally Posted by Kayle07
    Help me please! :(
    what's the coding for getting the average of only the odd numbers? I really I'm confuse and I'm still new in this programming.

    Pls help

    Code:
    //find the average of the odd numbers less than 100
    
    int Ave = 0, Total = 0, Count = 0;
    int Max = 100;
    
    for(int i=0; i<=Max ; i++)
    {
         if( i % 2 == 0)
         {
               Total += i;
               Count++;
         }
    }
    Ave = Total / Count;
    //print results
    PS I left a few bugs for you to find.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    95
    Rep Power
    4
    First find sum of all odd numbers and then divide it with total of of odd number.
    to check odd number you can use % operator.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0
    Thanks so much. it help me a lot. :)

IMN logo majestic logo threadwatch logo seochat tools logo