Question

Cant reach thi Fall 2018-Classwork #2 Then program should displays information about each value as follows v1Avg Of Even Digits ddd, Largest Digit d 2Avg Of Even Digits ddd, Largest Digit d Using C++ etc The program should use the following functions getAvgEvenDigits() afunction that takes one value and returns the average of even digits getHaxDigit( a lunction that takes one value and returns the maximum digit of thhe value The following are sample outputs 15 Avg of ven Digits Largest Digt Avg of tven DigitSE 2-66667, Largest DigitS 1Avg of Even Digits 2, Largest Digits Avg of Even Dagits: 2, Largest Digits Avg of Even Dagits: 1, Largest Dig 11 Avg of Even DigitstLargest Digit: 22Ang of Even Digits1 2, Largest Digit: 2 Avg of Even Digats:Largest Digit:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

//function to get the average of even integers

float getAvgEvenDigits(int n)

{

int sum,cnt;

cnt=0;

sum=0;

while(n)

{

if(n%2==0)

{

sum+=(n%10);

cnt++;

}

n/=10;

}

if(sum==0)

return(-1);

return((float)sum/cnt);

}

//function to get the maximum digit of the given number

int getMaxDigit(int n)

{

int max,i;

max=0;

while(n)

{

if((n%10)>max)

max=n%10;

n/=10;

}

return(max);

}

//function from where the execution of the program starts

int main()

{

//variable declaration

int n,i=0,j;

int arr[100];

cout<<"Enter the set of values(end with a 0 or -ve value : ";

while(1)

{

//inputting values

cin>>n;

if(n<=0)

break;

arr[i++]=n;

}

for(j=0;j<i;j++)

{

//displaying the results one by one

cout<<endl<<arr[j]<<" ==> "<<"Avg of Even Digits : "<<(getAvgEvenDigits(arr[j])>0?getAvgEvenDigits(arr[j]):0);

cout<<", Largest Digit : "<<getMaxDigit(arr[j]);

}

}

Sample Output:-

FCodestUntitled1.exe Enter the set of values (end with a 0 or-ve value 135 422 123 322 902 0 135Avg of Even Digits 0, Largest Digit : 5 422 > Avg of Even Digits : 2.66667, Largest Digit : 4 123 ==> Avg of Even Digits : 2, Largest Digit : 3 322 ==> Avg of Even Digits : 2, Largest Digit : 3 902-> Avg of Even Digits : 1, Largest Digit : 9 Process exited after 11.89 seconds with return value 0 Press any key to continue .

Please feel free to ask any doubts if you have in comments.

Please do upvote it!

Thank You!

Add a comment
Know the answer?
Add Answer to:
Can't reach thi Fall 2018-Classwork #2 Then program should displays information about each value as follows...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT