C++ Program to get sum of all odd numbers in given range




C++ Examples – Sum of ODD Numbers in the Given Range

#include<stdio.h>
#include <iostream>
using namespace std;

int main(){

  int number;
  int min,max;
  long sum =0;

  cout << "Enter the minimum range: ";
  cin >> min;

  cout << "Enter the maximum range: ";
  cin >> max;

  for(number = min;number <= max; number++)
    if(number % 2 !=0)
      sum = sum + number;

  cout << "Sum of odd numbers in given range is: " << sum;

  return 0;

}



/*
OUTPUT
Enter the minimum range: 25
Enter the maximum range: 30
Sum of odd numbers in given range is: 81

*/

Online computer science courses to jumpstart your future.
Different Ways of asking above question

  • C++ – Sum of ODD Numbers in the Given Range
  • C++ – write a program to calculate sum of all odd numbers
  • C++ – Program that prints odd numbers, even numbers and the numbers
  • C++ – Program to find out the sum of odd and even numbers between

 

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*