473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Output digits and the sum of digits assignment

6
Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

For example, it should output the individual digits of 3456 as 3 4 5 6; output the individual digits of 8030 as 8 0 3 0;
output the individual digits of 2345526 as 2 3 4 5 5 2 6; output the individual digits of 4000 as 4 0 0 0.




Expand|Select|Wrap|Line Numbers
  1.  #include<iostream> 
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7.  
  8.     int num,sum;
  9.  
  10.  
  11.     cout<<"Enter an integer number: ";
  12.     cin>>num;
  13.     cout<<endl;
  14.  
  15.  
  16.     cout<<"The individual digit you are entered is ";
  17.  
  18. {THIS PART DUNNO HOW TO DO.....PLS HELP ME COMPLETE THIS PART}
  19.  
  20. sum=0;
  21.     do
  22.     {
  23.         sum = sum + num % 10;
  24.         num = num / 10;
  25.     }
  26.     while (num>0);
  27.  
  28.     cout<<" and the sum of all the individual digit is "<<sum<<endl;
  29.  
  30.     return 0;
  31.  
  32. }
  33.  
Mar 26 '07 #1
6 9504
ocean
6
I Need The Answer By Today's Night....is Quite Urgent
Mar 26 '07 #2
svlsr2000
181 Expert 100+
just print num%10 in the loop
Mar 26 '07 #3
ocean
6
Expand|Select|Wrap|Line Numbers
  1.  #include<iostream> 
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7.  
  8. int num,sum;
  9.  
  10.  
  11. cout<<"Enter an integer number: ";
  12. cin>>num;
  13. cout<<endl;
  14.  
  15.  
  16. cout<<"The individual digit you are entered is ";
  17.  
  18. while (num>0)
  19. {
  20. num=num%10;
  21. }
  22.  
  23. ( IZZIT LIKE THAT ONLY???,,, I ALREADY TRY...BUT STILL CANNOT)
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. sum=0;
  35. do
  36. {
  37. sum = sum + num % 10;
  38. num = num / 10;
  39. }
  40. while (num>0);
  41.  
  42. cout<<" and the sum of all the individual digit is "<<sum<<endl;
  43.  
  44. return 0;
  45.  
  46. }
  47.  
Mar 26 '07 #4
ocean
6
just print num%10 in the loop



can you show me how to write.....pls
Mar 26 '07 #5
Ganon11
3,652 Expert 2GB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR

svlsr2000 has given you half the puzzle. You will use mod to determine the last digit, but then you must use division to shorten the number.
Mar 26 '07 #6
ocean
6
ooo, is like that wan....ok, me understand .... thanks for people who reply my question.....



thanks ya.....
Mar 26 '07 #7

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

Similar topics

14
by: srikanth | last post by:
static char buf = {1,2,3,4,5,6,7,8}; printf("Address: %u : Val = %d \n",(int*)buf+1,*((int*)buf+1)); Thanks Vija
5
by: Abe Simpson | last post by:
Hello all, The application I am working on must never output numbers in a floating-point format, that is, something like 2e-002 is a big no-no. At the same time, it must output numbers in a...
2
by: Jens Bloch Helmers | last post by:
How can I control the number of digits in the exponent when writing floats to a file? It seems that Python2.4.2(winXP) prints three digits anyway. >>> print 1.0e50 1e+050 >>> print '%e' %...
1
by: Martin | last post by:
Hi. My question seems to be somewhat primitive, but I cannot find an appropriate solution. Is it possible to control the number of digits displayed in the exponent part of the scientific...
8
by: Neil | last post by:
Hello Everyone.. I wrote a function called "totalsales" for a short business program I wrote, and I can't keep the decimal point aligned in the colums in the printf output statement. The data...
2
by: Ulrich Dorda | last post by:
I need a pytho nscript to read numbers(with loads of digits) from a file, do some basic math on it and write the result out to another file. My problem: I don't get python to use more digits: ...
4
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I am trying to convert the digits to even number so for example if I have 3 digit number, I want it to be 4 digit and If I have 5 digit number, I want it to be 6 digit. How can i...
5
by: m22j | last post by:
Hello, Hopefully you guys can help me out. I'm in "intro to programming" right now and I am using visual basic express 2008. The assignment that I have due is called passwordVerification. I have...
16
by: Okonita via DBMonster.com | last post by:
Hi all, I am comming along with all this Linus/DB2/scripting business...I am no longer scared of it!! (LOL). But, I need to create a .ksh script that does a REORGCHK and output only tables...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.