LAB-4
Read a multi-digit number (as chars) from the console. Develop a program to
print the frequency of each digit with suitable message.
num = int(input("Enter number: "))
print("Digit\tOccurrence")
for i in range(10):
count = 0
temp = num
while temp > 0:
a = temp % 10
if a == i:
count += 1
temp = temp // 10
if count > 0:
print(i,"\t\t",count)
Algorithm:
1. Start
2. Prompt the user to input a number.
3. Convert the input to an integer and store it in num.
4. Display the header: "Digit Occurrence".
5. Repeat the following steps for each digit i from 0 to 9:
• Initialize count to 0.
• Assign num to a temporary variable temp.
• While temp is greater than 0:
• Get the last digit of temp using temp % 10 and store it in a.
• If a is equal to i, increment count by 1.
• Remove the last digit from temp using integer division (temp = temp //
10).
• If count is greater than 0, print i and count.
6. End
Output:
Enter number: 122123321
Digit Occurrence
1 3
2 4
3 2