C++ program to find sum of Odd numbers

#include <iostream>
using namespace std;

int main()
 {
 int sumStore=0,i,Srange,Erange;
 cout<<"Enter start range ";
 cin>>Srange;
 cout<<"Enter End range ";
 cin>>Erange;
 for(i=Srange;i<=Erange;i++)
   {
      if(i%2!=0)
      {
         sumStore=sumStore+i;
      }
   }
   cout<<endl;
 cout<<"Sum of odd numbers from "<<Srange<<" to "<<Erange<<" is = "<<sumStore<<endl;
 return 0;
}

No comments:

Post a Comment