Write a C++ Program to find Sum of odd numbers between 1 and 100 using class

By | 28.12.2016

Write a C++ Program to find Sum of odd numbers between 1-100 using class

#include<iostream>
using namespace std;
class sum
{
   private:
        int n,s=0;
        public:
          void calc();
                void display();
                
};
void sum::calc()
{
        for(n=1;n<=100;n+=2)
        s=s+n;
        
}
void sum::display()
{
        cout<<"Sum of all odd numbers between 1-100:"<<s;
}
int main()
{
        sum s;
        s.calc();
        s.display();
        
}

 

4.3 3 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments