Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++, write a function that takes as a parameter an integer (as a long long va

ID: 3606373 • Letter: I

Question

In C++, write a function that takes as a parameter an integer (as a long long value) and prints the number of maximum, minimum and average of all digits. Format the output in two columns and round off all real numbers to four decimal places. Also write a program to test your solution. Hint: use the % and / operators to parse the input number into its digits. Your output should look like this one: Please, enter a long integer number 15441214892 Input number 15441214892 Largest digit: Smallest digit: Average of digits 3.7272 9 1

Explanation / Answer

Code:

#include<iostream>
using namespace std;

int main(){
int val, num, sum = 0, min=0, max=0, digitHere, i=0;
float avg,n=0;
cout << "Input number : ";
cin >> val;
num = val;
while (num != 0){
digitHere = num % 10;
sum = sum + digitHere;
num = num / 10;
if(digitHere > max){
max = digitHere;
}else{
max = max;
}
if(digitHere < min){
min = digitHere;
}else{
min = min;
}
n++;
}
avg = sum/n;
cout << "Largest digit :" << max << endl;
cout << "Smallest digit :" << min << endl;
cout << "Average of the digits "<< avg << endl;
}

Output: