Question #264939

Write a function that computes the average of the digits in an integer and use the following function header.double average Digits(long n)




Expert's answer

double averageDigits(long n) {
  int foo = 0, ln = 0;
    while (n > 0)
    {
        int dig = n % 10;
        foo += dig;
        n /= 10;
        ln++;
    }
    return foo/ln;
}
LATEST TUTORIALS
APPROVED BY CLIENTS