# Find the largest digit in a number

Problem statement:- Program to Find the largest digit in a number.

Example:

Input: num=55579462

Output: The Largest Digit is:

Input: num=213015

Output: The Largest Digit is:5

Data requirement:-

Input Data:- num

Output Data:-Largest

Program in C

### Here is the source code of the C Program to Find the largest digit in a number.

Code:

#include<stdio.h>
int main ()
{
int num, remider, Largest= 0;
printf ("Enter the Number :");
scanf ("%d", &num);

while (num > 0)
{
remider = num % 10;
if (Largest < remider)
{
Largest = remider;
}
num = num / 10;
}
printf ("The Largest Digit is :%d \n", Largest);
return 0;
}

Input/Output:
Enter the Number :
55579462
The Largest Digit is:9

Program in C++

### Here is the source code of the C++ Program to Find the largest digit in a number.

Code:

#include<iostream>
using namespace std;
int main ()
{
int num, remider, Largest= 0;
cout<<"Enter the Number :";
cin>>num;

while (num > 0)
{
remider = num % 10;
if (Largest < remider)
{
Largest = remider;
}
num = num / 10;
}
cout<<"The Largest Digit is "<< Largest;
return 0;
}

Input/Output:
Enter the Number :
213015
The Largest Digit is 5

Program in Java

### Here is the source code of the Java Program to Find the largest digit in a number.

Code:

import java.util.Scanner;
public class LargestDigit {

public static void main(String[] args) {
Scanner cs = new Scanner (System.in);
System.out.println ("Enter the number");
int num = cs.nextInt ();
int reminder, Largest= 0;
while (num > 0)
{
reminder = num % 10;
if (Largest< reminder)
{
Largest= reminder;
}
num = num / 10;
}
System.out.println("\nThe Largest Digit is "+Largest);

cs.close();
}
}

Input/Output:
Enter the number
457653
The Largest Digit is 7

Program in Python

### Here is the source code of the Python Program to Find the largest digit in a number.

Code:

print("Enter the Number :")
num=int(input())
Largest=0;
while (num > 0):
reminder=num%10
if Largest<reminder:
Largest = reminder
num =int(num / 10)
print("The Largest Digit is :", Largest)

Input/Output:
Enter the Number :
458791
The Largest Digit is: 9