By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 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


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

weaknessforcats
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.