# Find the Smallest digit in a number

Write a C program to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number in C.

Program in C

Code:

/*Write a C program to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number Using C*/

#include<stdio.h>
int main ()
{
int num, reminder;
printf ("Enter the Number :");
scanf ("%d", &num);
int smallest=num%10;
while (num > 0)
{
reminder = num % 10;
if (smallest> remider)
{
smallest = reminder;
}
num = num / 10;
}
printf ("The Smallest Digit is :%d \n", smallest);
return 0;
}

Input/Output:
Enter the Number :
4561237
The Smallest Digit is:1

Write a C++ program to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number in C++.

Program in C++

Code:

/*Write a C++ program to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number using C++*/

#include<iostream>
using namespace std;
int main ()
{
int num, reminder;
cout<<"Enter the Number :";
cin>>num;
int smallest=num%10;
while (num > 0)
{
reminder = num % 10;
if (smallest> reminder)
{
smallest = reminder;
}
num = num / 10;
}
cout<<"The Smallest Digit is : "<<smallest;
return 0;
}

Input/Output:
Enter the Number :
57894
The Smallest Digit is: 4

Write a JAVA program to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number in Java.

Program in Java

Code:

/*Write a JAVA program to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number using Java*/

import java.util.Scanner;
public class SmallestDigit {

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

Input/Output:
Enter the number
897897
The Smallest Digit is 7

Write a PYTHON to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number in Python.

Program in Python

Code:

'''Write a Python program to add find the Smallest digit in a number. or Write a program to add find the Smallest digit in a number using Python '''

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

Input/Output:
Enter the Number :
4567895
The Smallest Digit is  4

## C/C++/Java/Python Practice Question

1. class pro
{
public static int zee(int num)
{
int lastdigit;
int smallestnum=9;
while (num!=0)
{
lastdigit =num%10;// 654795
{
//5<=9
if (lastdigit<=smallestnum)
{
smallestnum=lastdigit;
}

}

num=num/10;

}
return smallestnum;

}
public static void main(String[] args)
{
int c;

c=zee(654795);
System.out.println(c);
}
}