- 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

To find the sum of odd numbers within a given range, the code is as follows −

<?php function odd_num_sum($val) { $entries = (int)($val + 1) / 2; $sum = $entries * $entries; return $sum; } function num_in_range($low, $high) { return odd_num_sum($high) - odd_num_sum($low - 1); } $low = 3; $high = 23; echo "The sum of odd natural numbers between the numbers 3 and 23 is ", num_in_range($low, $high); ?>

The sum of odd natural numbers between the numbers 3 and 23 is 141.75

A function named ‘odd_num_sum’ is defined that computes the sum of odd numbers within a specific range of numbers. The function ‘num_in_range’ gives the range of values between two numbers that are passed as parameters to this function. Outside both the function, the range values are defined and this function ‘num_in_range’ is called by passing the low and high values as parameters. Relevant output is displayed on the console.

- Related Questions & Answers
- Golang Program to Print Odd Numbers Within a Given Range
- 8086 program to find sum of odd numbers in a given series
- PHP program to find the numbers within a given array that are missing
- PHP program to find the sum of cubes of natural numbers that are odd
- C++ program to find numbers with K odd divisors in a given range
- How to find Kaprekar numbers within a given range using Python?
- Program to find count of numbers having odd number of divisors in given range in C++
- Finding sum of all numbers within a range in JavaScript
- Program to find the sum of first n odd numbers in Python
- Find numbers with K odd divisors in a given range in C++
- Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers
- Python program to generate random numbers within a given range and store in a list?
- Java program to generate random numbers within a given range and store in a list
- Write a Golang program to find prime numbers in a given range
- Java Program to create random BigInteger within a given range

Advertisements