![]() |
Given an odd number n, find the average of odd numbers from 1 to n. Input : n = 9 Output : 5 Explanation (1 + 3 + 5 + 7 + 9)/5 = 25/5 = 5 Input : n = 221 Output : 111
Method 1 We can calculate average by adding each odd numbers till n and then dividing sum by count. C
Javascript
Javascript
Output: 8 Time complexity: O(1) since performing constant operations Space Complexity: O(1) since using constant variables
|
Reffered: https://www.geeksforgeeks.org
Mathematical |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |