bsc

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

root / semester_2 / practice / prac_007.cpp

prac_007.cpp (475B)


      1 /* sum of natural numbers upto n */
      2 
      3 #include <iostream>
      4 using namespace std;
      5 
      6 class add {
      7     int inp, i, a = 0;
      8 
      9 public:
     10     void input();
     11     void calc();
     12     void output();
     13 };
     14 
     15 void add::input() {
     16     cout << "enter the number : ";
     17     cin >> inp;
     18 }
     19 
     20 void add::calc() {
     21     for (i = 1; i <= inp; i++) {
     22         a = a + i;
     23     }
     24 }
     25 
     26 void add::output() {
     27     cout << "Addtion = " << a;
     28 }
     29 
     30 int main() {
     31     add z;
     32     z.input();
     33     z.calc();
     34     z.output();
     35     return 0;
     36 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror