Jaydon
Jaydon

Reputation: 49

Need help splitting individual numbers from a starting number, then assign to integers

So I am trying to split a starting number and then assign each of those numbers to their own integers that can then be used in some equations for example:

Int Starting_Number = 8056
Int Four = 8
Int Three = 0
Int Two = 5
Int One = 6

The Problem I have ran into is that I can't make 500+ individual integers to be assigned for my input(which is the max length of my text box).

And second I am trying to multiply each of those numbers by their power Using the Example numbers above and add them together (which is where I am not sure how to do without knowing the integer names that get assigned whether by me or by some another method in the question above):

Int One = 6^0 = 6*0 = 0
Int Two = 5^1 = 5*1 = 5
Int Three = 0^2 = 0*0 = 0
Int Four = 8^3 = 8*8*8 = 512

0+5+0+512 = 517 (Ending Number)Result

Hopefully I explained that well, I am using Visual Studios C# Windows form application.

Thanks in advance. P.S. I work long shifts probably wont see this for a day or so...

Upvotes: -2

Views: 119

Answers (1)

jdweng
jdweng

Reputation: 34421

Try following :

           int Starting_Number = 8056;
            char[] digits = Starting_Number.ToString().ToCharArray();
            int results = (int)digits.Select((x, i) => Math.Pow(10, digits.Length - i - 1) * int.Parse(x.ToString())).Sum();  

Upvotes: -2

Related Questions