0% found this document useful (0 votes)
7 views1 page

Find FrequencyOfADigit

Uploaded by

Veena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Find FrequencyOfADigit

Uploaded by

Veena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

int main() {
int num, digit;
int frequency[10] = {0}; // Array to store the frequency of digits (0-9)

// Input a number
printf("Enter a number: ");
scanf("%d", &num);
// Make a copy of the number to avoid changing the original input
int temp = num;

// Calculate frequency of each digit


while (temp > 0) {
digit = temp % 10; // Get the last digit
frequency[digit]++; // Increment the frequency of the digit
temp /= 10; // Remove the last digit
}

// Display the frequency of each digit


printf("Frequency of each digit in %d:\n", num);
for (int i = 0; i < 10; i++) {
if (frequency[i] > 0) {
printf("Digit %d: %d times\n", i, frequency[i]);
}
}
for (int i = 0; i < 10; i++) {
printf("%d",frequency[i]);
}
}

You might also like