Print digits | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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

28th May 2021, 3:43 PM
Brianna
4 Respuestas
+ 1
Brianna you can use strings it will be more easier
28th May 2021, 4:59 PM
Atul [Inactive]
0
Most frequent digit means ? Last digit or more times appeared digits?
28th May 2021, 3:54 PM
Jayakrishna 🇮🇳
0
Frequent digit means more times appeared.
28th May 2021, 3:57 PM
Brianna
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...
28th May 2021, 6:06 PM
Jayakrishna 🇮🇳