English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How can i print out a number that will be divided by spaces
Example: 1234

print out 1*2*3*4*
or just 1 2 3 4

2007-03-20 12:35:17 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

Cout << "enter a number"
Cin >> number -----------------> (1234)

print out. 1 2 3 4

2007-03-20 12:53:00 · update #1

3 answers

If it's a homework assignment, then this is probably how your teacher doesn't want you to do it: simply use the C function sprintf() to print the integer a character buffer, then prints the contents character by character, with a space added.

Alternatively, you could divide the number by 10, immediately multiply it by 10 and subtract the resulting number from the original one; the difference is the right most digit. Divide by 10, and then repeat the above to get next digit(s), until the number equals zero. Of course, this would result in the sequence of digits in reverse order, but you should be able to fix that.

2007-03-20 13:33:28 · answer #1 · answered by Anonymous · 0 0

Append each time a space " " after you output each number!

2007-03-20 19:50:53 · answer #2 · answered by Coosa 2 · 0 0

int num;

cout<<"Enter a number";
for(int i=0;i<4;i++)
{
cin>>num[i];
cout<<" ";
}

2007-03-21 07:22:03 · answer #3 · answered by Jenna 3 · 0 1

fedest.com, questions and answers