csansoon

P3.03 X01646 Sum of digits (2)

Oct 2nd, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.21 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int b, n,i=0;
  6.     cin >> b;
  7.     while (cin >> n) {
  8.         cout << n << ": ";
  9.         while (n!=0) {
  10.             i=i+(n%b);
  11.             n=n/b;
  12.         }
  13.         cout << i << endl;
  14.         i=0;
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment