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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started