Python program to find the difference between greatest and smallest digits presents in the number


Write a program in python to find the difference between greatest and smallest digits present in the number

-------------------------------------------------

num=int(input("Enter any Number"))
min=9
max=0
while(num>0):
    digit=num%10;
    if(min>digit):
        min=digit;
    if(max<digit):
        max=digit;
    num=num//10;
diff=max-min
print("Greatest  Digit : ",max);
print("Smallest  Digit : ",min);
print("Difference  Between Greatest and Smallest  Digit : ",diff); 
-------------------------------------------------

output :- 

Enter any Number8971521

Greatest  Digit :  9
Smallest  Digit :  1

Difference  Between Greatest and Smallest  Digit :  8

Post a Comment

0 Comments