satriafu5710

Menghitung Jumlah Digit Angka Integer C++

Nov 22nd, 2021
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     int angka, jumlahDigit = 0;
  8.  
  9.     cout << "\n\t Menghitung Jumlah Digit Angka Integer \n\n";
  10.  
  11.     cout << " Masukkan Angka Integer : ";
  12.     cin >> angka;
  13.  
  14.     while (angka != 0)
  15.     {
  16.         jumlahDigit = jumlahDigit + angka % 10;
  17.  
  18.         angka = angka / 10;
  19.     }
  20.  
  21.     cout << "\n Jumlah Digit Angkanya : " << jumlahDigit;
  22.  
  23.     cout << endl
  24.          << endl;
  25. }
Add Comment
Please, Sign In to add comment