GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Feb-2007, 00:26
Dave101 Dave101 is offline
New Member
 
Join Date: Feb 2007
Posts: 2
Dave101 is on a distinguished road
Thumbs up

Calculate Sum of each position of an integer


Hello Everybody

I would greately appreciate if Somebody could tell me how to calculate Sum of each position of an integer in C like if there is 123 then it should give 1+2+3=6 and similary if it is 1237838 then it should give 1+2+3+7+8+3+8=32

Thank you.

Dave
  #2  
Old 16-Feb-2007, 02:06
mathematician mathematician is offline
Member
 
Join Date: Nov 2006
Location: Shrewsbury Uk
Posts: 133
mathematician will become famous soon enough

Re: Calculate Sum of each position of an integer


CPP / C++ / C Code:
// num = number whose digits are to be totalled
 
sum = 0;
 
while( num != 0 ) 
{
    sum += num % 10;
    num /= 10;
}
Last edited by LuciWiz : 19-Feb-2007 at 11:34. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fortran problem... Justin Fox Miscellaneous Programming Forum 6 24-Oct-2006 16:30
Check your keyword position using Google API jrobbio Search Engine Optimization Forum 5 20-Jul-2006 16:29
Help with integer inputs jrl134 C++ Forum 1 20-Feb-2005 01:36
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
there are some errors but where?? small_ticket C Programming Language 6 18-May-2004 14:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:17.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.