Largest digit - Finding Largest Digit of a Number Complete the program so that i
ID: 3728408 • Letter: L
Question
Largest digit - Finding Largest Digit of a Number Complete the program so that it reads a single integer input value, and prints a single line of output with the largest digit in the decimal representation of the input value. For example, if the input value is 483, then the output should be because 8 is the largest digit in the decimal representation of 483 Other examples: 567912 9 2563 6 Hints Use a while loop. Think about how the loop can make progress and what the loop condition should be . The loop should iterate through the digits of the input value · If n is the input value, n%le is the rightmost digit, and n/10 is an integer with all of the digits of n except for the rightmost digit Think about what loop variables will be needed, and how they should be updated in the loop.Explanation / Answer
#include<stdio.h>
main()
{
int n,max=0,rem;
printf("Enter the value:");scanf("%d",&n);
while(n)
{
rem=n%10;
if(rem>max)
{
max=rem;
}
n=n/10;
}
printf("%d",max);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.