Find summation of even number from 1 to 100 using class and object
Solution in c++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<bits/stdc++.h>
using namespace std;
class student
{
public:
int number,sum=0;
void calculation(int);
void putdata();
};
void student::calculation(int n)
{
for(int i=1; i<=n; i++)
{
if(i%2==0)
{
sum+=i;
}
}
}
void student::putdata()
{
cout<<sum<<endl;
}
int main()
{
student x;
int nm=100;
x.calculation(nm);
x.putdata();
}
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<bits/stdc++.h>
using namespace std;
class student
{
public:
int number,sum=0;
void calculation(int);
void putdata();
};
void student::calculation(int n)
{
for(int i=1; i<=n; i++)
{
if(i%2==0)
{
sum+=i;
}
}
}
void student::putdata()
{
cout<<sum<<endl;
}
int main()
{
student x;
int nm=100;
x.calculation(nm);
x.putdata();
}
No comments