எண்ணிக்கையிலான இலக்கங்களின் தொகை (sum of digits of a number)
அறிமுகப்படுத்துதல் (Introduction)
கேள்வி கூற்று – வினா / (Problem Statement)
e.g. 1, 2, 1729, 314159, 355, 113, 1001, etc.
e.g. 1 -> 1, 2->2, 1729 -> 1+7+2+9 = 19, 314159 -> 3 + 1 + 4 + 1 + 5 + 9 = 23, etc.
யோசனை/ (Solution Idea)
- 10 மூலம் எண்ணிக்கையை வகுப்பதன், மற்றும் எஞ்சிய எடுத்து கணக்கிடலாம். மட்டு ஆபரேட்டர் “%” மற்றும் பிரிவு “/” பயனுள்ளதாக இருக்கும். Dividing the number by 10, and take the remainder. Modulo operator “%” and division “/” are useful.
- sum = 0; எண் = 1279; எஞ்சிய = 9 = 1279%10; வகுப்பதன் = 127 = (1279/10) ;
- எஞ்சியவை சேர்த்து வைத்துக்கொள்ள. Add remainder to the total.
- sum = sum + எஞ்சிய.
- ஆதாய பங்கு >= 0 வரை, 4 – படிகள் 1 செய்யவும். Repeat steps 1 – 4, with the dividend as the new number until dividend > 0.
அனைத்து ஒன்றாக நீங்கள் அதை வைத்து (Putting it all together you get),
# இது ஒரு எழில் தமிழ் நிரலாக்க மொழி உதாரணம் # sum of digits of a number # எண்ணிக்கையிலான இலக்கங்களின் தொகை நிரல்பாகம் எண்_கூட்டல்( எண் ) தொகை = 0 @( எண் > 0 ) வரை d = எண்%10; பதிப்பி "digit = ",d எண் = (எண்-d)/10; தொகை = தொகை + d முடி பின்கொடு தொகை முடி பதிப்பி எண்_கூட்டல்( 1289)#20 பதிப்பி எண்_கூட்டல்( 123456789)# 45
நீங்கள் நிரலை ezhillang.org முயற்சி செய்யலாம்; You can try out the code at ezhillang.org
வாசிப்பு நன்றி, மற்றும் உங்கள் கருத்துக்களை பகிர்ந்து கொள்ள!
அன்புடன்,
முத்து
Thanks for reading, and share your comments!
Regards,
Muthu