473,386 Members | 1,752 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.

Using a loop to do this...

Basically getting a five digit number with a long unsigned variable,
and making the output like this:
number is 63424
6
3
4
2
4

Using loops, does anyone know how to start this? I'm thinking of using
powers of 10, % and a while loop...

Thanks

Oct 1 '05 #1
4 1046

snow.carri...@gmail.com wrote:
Basically getting a five digit number with a long unsigned variable,
and making the output like this:
number is 63424
6
3
4
2
4

Using loops, does anyone know how to start this? I'm thinking of using
powers of 10, % and a while loop...

Thanks


On the right track.
(63424 - 63420) / 1 = 4
(63420 - 63400) / 10 = 2
etc...

Oct 1 '05 #2
Thanks, but how would you incorporate that into a while loop?

Oct 1 '05 #3
> Using loops, does anyone know how to start this? I'm thinking of using
powers of 10, % and a while loop...


Does this helps?

unsigned long number;
cin >> number;

for(int times=0, dig=10000; times < 5; ++times, dig/=10){
cout << number/dig%10 << endl;

Oct 1 '05 #4
sn***********@gmail.com wrote:
Thanks, but how would you incorporate that into a while loop?


It seems odd that the implementation has to use a while loop. A
loopless solution is perfectly reasonable:

#include <iostream>

void PrintDigits(int num)
{
if (num > 9)
PrintDigits(num/10);

std::cout << num%10 << std::endl;
}

int main()
{
PrintDigits(12345);
}

Output:
1
2
3
4
5

Surely the above solution would work just as well for your purposes.

Greg

Oct 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: doomx | last post by:
I'm using SQL scripts to create and alter tables in my DB I want to know if it's possible to fill the description(like in the Create table UI) using these scripts. EX: CREATE TABLE(...
5
by: John Dumais | last post by:
Hello, I have been trying to figure out how to write an array of doubles (in this specific case) to a binary stream without using a loop. What I have been doing is... foreach(double d in...
13
by: Bev in TX | last post by:
We are using Visual Studio .NET 2003. When using that compiler, the following example code goes into an endless loop in the "while" loop when the /Og optimization option is used: #include...
9
by: George McCullen | last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
1
by: Thiero | last post by:
Hi I posted s thread but did have any reply, I am a new programmer and really wants someone to help me on how to use TreeMap for this code cos I want to it to be able to handle the options from 6...
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
4
by: GeekBoy | last post by:
I am reading a file of numbers using for loops. The numbers are in a grid as follows: 8 36 14 11 31 17 22 23 17 8 9 33 23 32 18 39 23 25 9 38 14 38 4 22 18 11 31 19 16 17 9 32 25 8 1 23
1
by: sksksk | last post by:
I want to achieve the following process in the smarty for $item one i should be able to get the value using loop.index, but without any luck. any help is appreciated. <?php for ($i = 1; $i...
5
by: dbrother | last post by:
Access 2003 Win XP Pro SP3 Using SQL /ADO Recordsets in a Do Loop Hello, I'm using a random number generator based on an integer input from a user from a form that will get X number of random...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...

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.