Instructions:
Input
1. An integer
Output
The first line will contain a message prompt to input the integer.
The second line contains the largest digit of the integer.
Enter·n:·214
Largest·digit·=·4
#include <stdio.h>
int main()
{
int n,d;
int max = -1;
printf("Enter n: ");
scanf("%d", &n);
while (n != 0)
{
d = n % 10;
if (d > max)
max = d;
n /= 10;
}
printf("Largest digit = %d", max);
return 0;
}
Comments
Leave a comment