Header Ads

WAP to Print the Largest Digit in any given Number in C - 43

This program prints the Largest Digit in any given Number in C

Program Code:

/*  Write a C program to find a Largest Digit in a Number  */ 

#include <stdio.h>
int main() 
{
        int num, large = 0, rem = 0;

        /* get the input from the user */
        printf("Enter a Number : ");
        scanf("%d", &num);

        /* finding the largest digit of the given input */
        while (num > 0) 
 {
                rem = num % 10;
                if (rem > large) 
  {
                        large = rem;
                }
                num = num / 10;
        }

        /* print the largest digit of the number */
        printf("Largest Digit of the Number is : %d\n\n", large);
        return 0;
  }

Program Output:

No comments