#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:-
Please feel free to ask any doubts if you have in comments.
Please do upvote it!
Thank You!
Can't reach thi Fall 2018-Classwork #2 Then program should displays information about each value as follows...