Answer to Question #264939 in C++ for Keshi

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)




1
Expert's answer
2021-11-12T00:55:12-0500
double averageDigits(long n) {
  int foo = 0, ln = 0;
    while (n > 0)
    {
        int dig = n % 10;
        foo += dig;
        n /= 10;
        ln++;
    }
    return foo/ln;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS