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 the 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 the biggest digit.
For example if the input is 1234...the output should be 4.
Please modify....do not write another program. If you just copy paste another code I will ask my colleagues to give you multiple bad ratings and report you to chegg which will lead to your account being closed
#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
Get step-by-step solutions from verified subject matter experts
