473,657 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Output digits and the sum of digits assignment

6 New Member
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 9532
ocean
6 New Member
I Need The Answer By Today's Night....is Quite Urgent
Mar 26 '07 #2
svlsr2000
181 Recognized Expert New Member
just print num%10 in the loop
Mar 26 '07 #3
ocean
6 New Member
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 New Member
just print num%10 in the loop



can you show me how to write.....pls
Mar 26 '07 #5
Ganon11
3,652 Recognized Expert Specialist
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 New Member
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
2447
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
6766
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 compact way, that is, it should only output significant digits, and only output a decimal point if there are digits following it.
2
3252
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.0e50) 1e+050 I would prefer two digits in the exponent. Usually 3 digits is not a problem, except for waisted disk space in 99.999999% of all practical
1
1847
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 notation? I can use 'precision()' member function or 'setprecision' manipulator to control the number of digits after the point: cout.setf(ios_base::scientific, ios_base::floatfield); cout.precision(8);
8
1784
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 comes from an array sales, which is passed to the function . like ---- Tracey John Terry 0.00 10.00 51.00
2
6197
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: In order to try this I type: The normal precision one: 1.2345678912345679000000000e+000
4
4214
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 do it in C# Below is what I am trying to di number = 123 I want it to be
5
3023
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 to verfy that the password somebody picks is at least 6 characters long and contains numeric digits and alphabetic characters. I have been working on this assignment for what feels like forever now. Also the verification must be wrote as a function. ...
16
4835
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 recommended for reorg. My goal is to reorgchk and run reorgs based on entries in this reorg file as shown in the example below. I have tried my hand at the following failing script and hope that gurus here can throw me a lifeline of examples on how to...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.