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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.