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. - #include<iostream>
-
using namespace std;
-
-
-
int main()
-
{
-
-
int num,sum;
-
-
-
cout<<"Enter an integer number: ";
-
cin>>num;
-
cout<<endl;
-
-
-
cout<<"The individual digit you are entered is ";
-
-
{THIS PART DUNNO HOW TO DO.....PLS HELP ME COMPLETE THIS PART}
-
-
sum=0;
-
do
-
{
-
sum = sum + num % 10;
-
num = num / 10;
-
}
-
while (num>0);
-
-
cout<<" and the sum of all the individual digit is "<<sum<<endl;
-
-
return 0;
-
-
}
-
6 9532
I Need The Answer By Today's Night....is Quite Urgent
just print num%10 in the loop
- #include<iostream>
-
using namespace std;
-
-
-
int main()
-
{
-
-
int num,sum;
-
-
-
cout<<"Enter an integer number: ";
-
cin>>num;
-
cout<<endl;
-
-
-
cout<<"The individual digit you are entered is ";
-
-
while (num>0)
-
{
-
num=num%10;
-
}
-
-
( IZZIT LIKE THAT ONLY???,,, I ALREADY TRY...BUT STILL CANNOT)
-
-
-
-
-
-
-
-
-
-
-
sum=0;
-
do
-
{
-
sum = sum + num % 10;
-
num = num / 10;
-
}
-
while (num>0);
-
-
cout<<" and the sum of all the individual digit is "<<sum<<endl;
-
-
return 0;
-
-
}
-
just print num%10 in the loop
can you show me how to write.....pls
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.
ooo, is like that wan....ok, me understand .... thanks for people who reply my question.....
thanks ya.....
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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.
|
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
|
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);
|
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
| |
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
|
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
|
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.
...
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |