எண்ணிக்கையிலான இலக்கங்களின் தொகை (sum of digits of a number)
அறிமுகப்படுத்துதல் (Introduction)
எல்லோருக்கும் வணக்கம்! நான் ஒரு போது இந்த வலைப்பதிவு இடுகை எதிர்பார்த்து இருந்தது.
இந்த இடுகையில், இலக்கங்களின் தொகை கணக்கிட எவ்வாறு, நான் எப்படி காண்பிக்கிறேன்.
Hello everyone! I am excited to show you how to calculate the sum of digits of a number, in Ezhil language, through this blog post.
கேள்வி கூற்று – வினா / (Problem Statement)
ஒரு எண் என்ன? இது இலக்கங்களின் ஒரு சரம். What is a number? It is a string of digits.
e.g. 1, 2, 1729, 314159, 355, 113, 1001, etc.
மேலே காட்டப்பட்டுள்ள எண்களை, எண்ணிக்கையிலான இலக்கங்களின் தொகை; the sum of digits for above numbers.
e.g. 1 -> 1, 2->2, 1729 -> 1+7+2+9 = 19, 314159 -> 3 + 1 + 4 + 1 + 5 + 9 = 23, etc.
யோசனை/ (Solution Idea)
இது எளிதாக இருந்தது! ஆனால் நமது பிரச்சனை இதை ஒரு நிரல் எழுதுவது இருக்கிறது. This was easy! But our problem is to write a program for doing this.
எண் 1279 பரிசீலிக்க. Consider the number 1279.
- 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
நிரல்பாகம் எண்_கூட்டல்( எண் )
தொகை = 0
@( எண் > 0 ) வரை
d = எண்%10;
பதிப்பி “digit = “,d
எண் = (எண்-d)/10;
தொகை = தொகை + d
முடி
பின்கொடு தொகை
முடி
பதிப்பி எண்_கூட்டல்( 1289)#20
பதிப்பி எண்_கூட்டல்( 123456789)# 45
இவற்றிக்கு உரிய ஆங்கில நிரலையும் எழுதினால் ஒப்பிட்டு கற்க உதவியாக அமையும். 🙂
Puvipavan கருத்திற்கு நன்றி. இவற்றிக்கு உரிய ஆங்கில நிரலையும் இந்த லிங்கில் பார்க்க
http://rosettacode.org/wiki/Sum_digits_of_an_integer