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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.