Hi all, I am new to C programming, can anyone help me out with a solution to find sum of digits of a 5-digit number without using control statements, like if, for... thank you
sakthi_2001
0
Newbie Poster
Recommended Answers
Jump to PostSorry. I thought this was in C++ ...
make an array, loop through, and sum:
int total = 0; int array[ARRAY_SIZE]; /* Fill array with info */ for [0 -> ARRAY_SIZE-1] total = total + array[CURRENT_POSITION] print "Sum: " total
Obviously that's psuedo code.
Jump to Post[...] to find sum of digits of a 5-digit number without using control statements, like if, for... thank you
make an array, loop through, and sum:
Read the question again?
Jump to PostMaybe you could use the modulus operator and recursion?
All 10 Replies
twomers
408
Posting Virtuoso
Aia
1,977
Nearly a Posting Maven
iamthwee
commented:
NIce catch
+11
iamthwee
twomers
408
Posting Virtuoso
Dave Sinkula
2,398
long time no c
Team Colleague
Aia
1,977
Nearly a Posting Maven
iamthwee
twomers
408
Posting Virtuoso
iamthwee
twomers
commented:
Please forgive me :(
+3
twomers
408
Posting Virtuoso
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.