Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimizing Data Collection In Warzones

Authors: Aaget Aamber

1st Edition

B0CQRRFP5F, 979-8869065902

More Books

Students also viewed these Databases questions

Question

If ( A^2 - A + I = 0 ), then inverse of matrix ( A ) is?

Answered: 1 week ago

Question

What is computer neworking ?

Answered: 1 week ago