- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Average of odd numbers till a given odd number?

The average of odd numbers till a given odd number is a simple concept. You just need to find odd numbers till that number then take their sum and divide by the number.

If average of odd number till n is to be found. Then we will find odd numbers from 1 to n add then divide it by the number of odd number.

## Example

Average of odd number till 9 is 5 i.e.

1 + 3 + 5 + 7 + 9 = 25 => 25/5 = 5

There are two methods for calculating the average of odd number till n which is an odd number.

- Using Loops
- Using Formula

## Program to find the average of odd number till n using loops

To calculate the average of odd numbers till n, we will add all numbers till n and then divide in by the number of odd number till than.

Program to calculate the average of odd natural numbers till n −

## Example Code

#include <stdio.h> int main() { int n = 15,count = 0; float sum = 0; for (int i = 1; i <= n; i++) { if(i%2 != 0) { sum = sum + i; count++; } } float average = sum/count; printf("The average of odd numbers till %d is %f",n, average); return 0; }

## Output

The average of odd numbers till 15 is 8.000000

## Program to find the average of odd numbers till n using Formula

To calculate the average of odd numbers till n we can use a mathematical formula (n+1)/2 where n is an odd number which is the given condition in our problem.

Program to calculate the average of odd natural numbers till n −

## Example Code

#include <stdio.h> int main() { int n = 15; float average = (n+1)/2; printf("The average of odd numbers till %d is %f",n, average); return 0; }

## Output

The average of odd numbers till 15 is 8.000000

- Related Questions & Answers
- Average of even numbers till a given even number?
- Average of first n odd naturals numbers?
- Write a number array and add only odd numbers?
- Golang Program to Print Odd Numbers Within a Given Range
- 8086 program to find sum of odd numbers in a given series
- Even numbers at even index and odd numbers at odd index in C++
- N consecutive odd numbers JavaScript
- PHP program to find the sum of odd numbers within a given range
- Program to find count of numbers having odd number of divisors in given range in C++
- Squared sum of n odd numbers - JavaScript
- Express an odd number as sum of prime numbers in C++
- Find the Number of Subarrays with m Odd Numbers using C++
- Sum of square of first n odd numbers
- Find numbers with K odd divisors in a given range in C++
- C++ Program to calculate the number of odd days in given number of years