Advertisement
H-a-y-K

Untitled

Nov 30th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. double average(int num)
  4. {
  5.     double sum = 0;
  6.     int len = 0;
  7.  
  8.     while (num > 0)
  9.     {
  10.         len++;
  11.         sum += num % 10;
  12.         num /= 10;
  13.     }
  14.  
  15.     return sum / len;
  16. }
  17.  
  18. int main() {
  19.   std::cout << average(221584);
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement