Q:

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

0

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

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#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();
        
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Classes and Objects Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C++ program to display Entered Time using ... >>
<< Write a C++ Program to find Largest among 3 number...