Question: In C programing....This program prints most occuring digit in a number. Modify so that for a number with no repeating digits to print th biggest

In C programing....This program prints most occuring digit in a number. Modify so that for a number with no repeating digits to print th biggest digit.

For example if the input is 1234...the output should be 4

#include

int mosOccDig(int n) {

//array to count the number of times each digit appears

int count[20] = {0};

// Iterate through the digits of the number

while (n > 0) {

int digit = n % 10;

count[digit]++;

n /= 10;

}

// most occurring digit

int max_count = 0;

int mos_occ_dig = 0;

for (int i = 0; i < 10; i++) {

if (count[i] > max_count) {

max_count = count[i];

mos_occ_dig = i;

}

}

return mos_occ_dig;

}

int main() {

int n;

scanf("%d", &n);

printf("Most occurring digit from %d is %d", n, mosOccDig(n));

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!