I spent 4 hours trying to find out how I can add the digits of a number. Could you give me an idea?
Adnan S.
0
Newbie Poster
Recommended Answers
Jump to PostSorry Thinker but you program doesn't hack it. Its full of syntax errors and undeclared variables, and it just plain doesn't work right. Line 10 does NOT calculate the sum of the digits. If the input number is 15 then the sum of the digits is 1 + 5 = …
Jump to Post#include <stdio.h> int main() { int n = 12345; int sum = 0; while (n != 0) { int c = n%10; sum += c; n /= 10; } printf("The sum is %d\n", sum); return 0; }
this should work just fine
Jump to Post> sorry buddy just try this out...
> #include<stdio.h>
> #include<conio.h>
> void main()Great, just what we want around here, another void main, conio.h riddled post without code tags.
Jump to Post...
Read this, it applies to your program. (conio, void main(), getch clrscr are bad coding habits)
Next: read this to learn how to make a senseable post
Then read this about code tags
And learning what
Jump to Postu cn jst tr ds out dat cn wrk 4 any num f long integer range sch as 123456789 etc.,
Would you like to try that again in English?
Tada: the rulebook
- do not use
All 30 Replies
Aia
1,977
Nearly a Posting Maven
thinker
-4
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Jishnu
160
Posting Pro
thinker
-4
Newbie Poster
doublex
1
Newbie Poster
Ab000dy_85
commented:
This look very well done, why there are more posts after yours :/
+1
thinker
-4
Newbie Poster
Ancient Dragon
commented:
no code tags
-4
doublex
1
Newbie Poster
Salem
5,138
Posting Sage
thinker
-4
Newbie Poster
rajusankar28
0
Newbie Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
emmwithjesus
-9
Newbie Poster
Salem
commented:
Completely illiterate, 6 months late, and no code tags.
-4
Ancient Dragon
commented:
Ditto what Salem said
-5
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
MustyCE
0
Newbie Poster
akshay.thakur
-5
Newbie Poster
Ancient Dragon
commented:
Create your own thread.
-5
qasimhasnain
-7
Newbie Poster
Ancient Dragon
commented:
huh?
-7
mridul.ahuja
4
Coding Enthusiast
saguna.saha
-3
Newbie Poster
deceptikon
commented:
Please look at thread dates before posting. Thanks.
-3
Ramya murugan
-3
Newbie Poster
deceptikon
commented:
Please look at thread dates before posting. Thanks.
-3
ashokkumar01cbe
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
ashokkumar01cbe
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
samson.dadson.3
0
Newbie Poster
samson.dadson.3
0
Newbie Poster
samson.dadson.3
0
Newbie Poster
rayhaneh
0
Newbie Poster
Unsa
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.