bsc

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

root / semester_2 / practice / prac_009.cpp

prac_009.cpp (539B)


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