Write a c++ program to calculate sum of 1st fifty odd nos. Using constructor program.
Answers
Answered by
0
#include <iostream>
using namespace std;
class Oddsum
{
private:int sum = 0;
int n = 50;
void gen_odd_sum(){
for ( int i = 1;i <n;i +=2){
sum+=i;
}
public:
Oddsum(int num) {
n = num;
gen_odd_sum();}
Oddsum()
{
gen_odd_sum();}
void print_odd_nos() {
cout<<sum;}
};
int main()
{
Oddsum ob;
ob.print_odd_nos();
return 0;
}
Similar questions
English,
6 months ago
Social Sciences,
6 months ago
Math,
11 months ago
English,
1 year ago
English,
1 year ago