bsc

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

prac_009.cpp (675B)


      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 digits */
      8 
      9 #include <iostream>
     10 using namespace std;
     11 
     12 class digitsum {
     13     int inp, a = 0, b = 0;
     14 
     15 public:
     16     void input();
     17     void calc();
     18     void output();
     19 };
     20 
     21 void digitsum::input() {
     22     cout << "enter the number :";
     23     cin >> inp;
     24 }
     25 
     26 void digitsum::calc() {
     27     while (inp > 0) {
     28         a = inp % 10;
     29         b = b + a;
     30         inp = inp / 10;
     31     }
     32 }
     33 
     34 void digitsum::output() {
     35     cout << "sum of the digits : " << b << ".";
     36 }
     37 
     38 int main() {
     39     digitsum z;
     40     z.input();
     41     z.calc();
     42     z.output();
     43     return 0;
     44 }
© 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