0
Print digits
I want my code to print the most frequent digit, with no arrays. My desired output is like the example below. Example: Input: 81712314 The output should be: 1 This is my code. https://code.sololearn.com/cA17a35a25a5
5 Réponses
+ 1
Brianna you can use strings it will be more easier
0
Most frequent digit means ?
Last digit or more times appeared digits?
0
Frequent digit means more times appeared.
0
Without arrays it's difficulty code but you can try like this :
81712314
Take num= n%10=4 remove it from original number and find how many left in number with another while loop innerly..
If n%10==digit then make count++; remove it from original number
Else add back to original number.
If count>=max , make max=count, maxd=digit
Ex: 81712314
digit=n%10=4, remain number=8171231, count=1,max=3 ,Nd=4
digit=1, number=8723, count=3, max=3,Nd=1,
digit=3, count=1, max=3, Nd=1,number=872
digit=2, count=1, max=3, Nd=1,number=87
digit=7, count=1, max=3, Nd=1,number=8
digit=8, count=1, max=3, Nd=1,number=0
Stop here, Nd=maxDigit, max=digit repeatedmax.
count++ when digit==n%10, and n=num*10+n%10 else n=n%10.
This way seems difficult but if you try, you can get it.
Easy way is to make it string and sort it and count frequency linearly..
Use of is more easy..
Hope it understandable .. try it and reply if need.. hope it helps...