#include<iostream> #include<string> #include<fstream> usingnamespacestd; intmain
ID: 3648569 • Letter: #
Question
#include<iostream>
#include<string>
#include<fstream>
usingnamespacestd;
intmain()
{
constintDigitNum=50;//arraycapacity
inthugeInt[DigitNum];//arrayholdingthehugeinteger
intfrequency[10];//occurrencefrequencyofeachdigit0..9
//i.e.frequency[0]thenumberoftimes0appearsinhugeInt
//i.e.frequency[1]thenumberoftimes1appearsinhugeInt
//...
//i.e.frequency[9]thenumberoftimes9appearsinhugeInt
chardigit;//holdingcurrentdigitduringthereading
intfreqIndex;//holdingthedigitoccuringmostfrequently
//readdigitsinthehugeintegervalueintothearrayhugeInt
read digits in the huge integer value into the array hugeInt
//Printthearraythathasbeenread
cout<<"Thehugeintegervalueis";
for(inti=0;i<DigitNum;i++)
cout<<hugeInt[i];
cout<<endl<<endl;
//1)initializethefrequencyarray
//2)calculatetheoccurrencefrequencyofeachdigit
//3)findthedigitwiththehighestoccurrencefrequency
1) initialize the frequency array 2) calculate the occurrence frequency of each digit 3) find the digit with the highest occurrence frequency
cout<<freqIndex<<"appearsmostfrequentlyinthehugeinteger."<<endl
<<"Itappears"<<frequency[freqIndex]<<"times."<<endl;
return0;
}Ask a question...
Explanation / Answer
//readdigitsinthehugeintegervalueintothearrayhugeInt for(i=0;i>hugeInt[i]; //1)initializethefrequencyarray for(i=0;i>frequency[i];Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.