Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get Spaces in Output in a mathematical way. It should go with something with Modulus technique or algorithmic approach.
For example

Enter: 12345
Output: 1 2 3 4 5

Been trying and searching and searching.... no sleep yet!
Posted

After you voted my first answer with a 1...

flance99 wrote:
Been trying and searching and searching.... no sleep yet!


So, you're looking for an answer to a homework question. If you really had been "searching and searching", you would have found this:

http://www.codeproject.com/Messages/3341745/Re-how-to-split-input-integer-variable-modified.aspx[^]

It looks like one of your classmates came here for an answer, too. While you'r4e looking at that, make sure you note who provided the answer he wanted, and make sure your read the entire post, because the note that follows the code applies to you, too.

I find it insulting that people taking a class on programming feel the need to scrounge around on established programmer sites looking for people to do they work they're supposed to be doing so they can learn the craft. IMHO, you guys are nothing but losers that have apparently chosen the wrong occupation.

BTW, the reason this is insulting is because I have to compete against people like you in the workplace. I don't mine losing out to a guy that's as good as or better than I am, but losing out to someone because they're cheaper yet not nearly as qualified really ticks me off.



 
Share this answer
 
v6
Are you really searching for a way to separate characters in a input string?
I.e. something similar to
String a = "12345";
foreach (char c in a)
{
  System.Console.Write(c);
  System.Console.Write(' ');
}
    System.Console.WriteLine();

?
 
Share this answer
 
Why use math when you can do it with the framework?

int value = 12345;
string text = string.Format("{0:0 0 0 0 0}", value);
 
Share this answer
 
Yes but I need to do this in a mathematical way. Something to do with the Modulus % approach. A Small algorithm for example. :(
 
Share this answer
 
C#
private static string Format(int number)
{
    string result = string.Empty;
    while (number > 0)
    {
        result = (number % 10).ToString() + ' ' + result;
        number /= 10;
    }
    return result;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900