C++ Program To Find The Sum Of Given Range (Using For Loop) - HelpMeOutAlways

Sunday, June 24, 2018

C++ Program To Find The Sum Of Given Range (Using For Loop)

Source Code

#include <iostream>
using namespace std;

int main(){

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

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

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

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

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

  return 0;

}

Output



No comments:

@way2themes