bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

prac_007.cpp (611B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 22 Jun 2026
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* sum of natural numbers upto n */
      8 
      9 #include <iostream>
     10 using namespace std;
     11 
     12 class add {
     13     int inp, i, a = 0;
     14 
     15 public:
     16     void input();
     17     void calc();
     18     void output();
     19 };
     20 
     21 void add::input() {
     22     cout << "enter the number : ";
     23     cin >> inp;
     24 }
     25 
     26 void add::calc() {
     27     for (i = 1; i <= inp; i++) {
     28         a = a + i;
     29     }
     30 }
     31 
     32 void add::output() {
     33     cout << "Addtion = " << a;
     34 }
     35 
     36 int main() {
     37     add z;
     38     z.input();
     39     z.calc();
     40     z.output();
     41     return 0;
     42 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror