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

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.