By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,054 Members | 1,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,054 IT Pros & Developers. It's quick & easy.

plz tell me how to do the below program

P: 1
ask the user to enter a number
a)get separate digits of this number
b)find the sum of the digits
Oct 30 '17 #1
Share this Question
Share on Google+
2 Replies

P: 3
This is a homework question!
Oct 30 '17 #2

Expert Mod 5K+
P: 9,197
Use the itoa() function. This will convert the integer to a string.

Then just run a loop to display the digits.

As you display each digit you can add its value to a total which you can display after the string has displayed.

BTW keep in mind that displaying digits this way uses the ASCII value of the digit. You will need to subtract the offset into the ASCII table to get the numeric value of the digit.
Oct 30 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.