C Program to find largest digit of a number


In this program, You will learn how to find largest digit of a number in c.


1234 => Largest digit is: 4


Example: How to find largest digit of a number in c

Run it Now
#include<stdio.h>

int main() {

   int num, r, ld = 0;

   printf("Enter a Number :");
   scanf("%d", &num);

   while (num > 0) {
       r = num % 10;
       if (ld < r) {
           ld = r;
       }
       num = num / 10;
   }
   printf("\nThe Largest Digit is :%d", ld);

   return 0;
}

Output:

Enter a Number :191
The Largest Digit is :9