Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 26th, 2013, 04:05 AM
 Kayle07
Registered User

Join Date: Aug 2013
Posts: 2
Time spent in forums: 13 m 50 sec
Reputation Power: 0
Odd numbers counting

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
August 26th, 2013, 04:11 AM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,539
Time spent in forums: 2 Months 3 Days 9 h 11 m 6 sec
Reputation Power: 4106
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

#3
August 26th, 2013, 04:21 AM
 TechNoFear
Offensive Member

Join Date: Oct 2002
Location: in the perfect world
Posts: 622
Time spent in forums: 3 Days 18 h 33 m 41 sec
Reputation Power: 27
Quote:
 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

#4
August 26th, 2013, 04:21 AM
 eramit2010
Contributing User

Join Date: Mar 2013
Location: India
Posts: 95
Time spent in forums: 2 Days 18 h 10 m
Reputation Power: 3
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.

#5
August 27th, 2013, 06:08 AM
 Kayle07
Registered User

Join Date: Aug 2013
Posts: 2
Time spent in forums: 13 m 50 sec
Reputation Power: 0
Thanks so much. it help me a lot.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Odd numbers counting