NotAlpha102

Digits

Mar 7th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. /*When declaring function, use the data type you want the output
  4. in throughout the entire function build*/
  5. int converter(int num, int base);
  6. int counter(int n);
  7. main()
  8. {
  9.     int n, base, conv;
  10.     scanf("%d %d", &n, &base);
  11.     conv=converter(n,base);
  12.     //printf("%d\n", conv);
  13.     printf("%d", counter(conv));
  14. }
  15. int converter(int num, int base)
  16. {
  17.     int rim, converted, i=0;
  18.     while(num!=0)
  19.     {
  20.         rim=num%base;
  21.         num=num/base;
  22.         converted=rim+rim*pow(10,i);
  23.         i++;
  24.     }
  25.     return converted;
  26. }
  27. int counter(int n)
  28. {
  29.     int cnt=0;
  30.     while(n!=0)
  31.     {
  32.         n=n/10;
  33.         cnt++;
  34.     }
  35.     return cnt;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment