Home > Net >  How to use the method of integer more than o c # each output an integer.
How to use the method of integer more than o c # each output an integer.

Time:10-02

Mathematical point of view about the idea of form a complete set, the source code, of course, better!

CodePudding user response:

Num % 10 can obtain digital lowest
And then kept num/=10 modulus can get all of the position

CodePudding user response:

The static void the Get (int a)
{
Int len=a.T oString (). The Length;
For (int I=len - 1; I & gt;=0; I -)
{
Int b=a/(int) Math. Pow (10, I) % 10;
Console. WriteLine (b.T oString ());
}
}

CodePudding user response:


Said nothing to tell mathematical Angle, the best you can as f (x) (g), but c # func temporarily does not support the yield return, so I give examples for the way the recursive implementation

 int numsource=541; 

Var res=getnum (numsource). ToList ();
IEnumerable Getnum (int num)
{
If (num/10 & gt; 0)
{
Var temp=getnum (num/10);
Foreach (var I in temp)
{
Yield return I;
}
}

Yield return num % 10;
}

CodePudding user response:

In 345, for example

345/1%10 - & gt; 5
345/10%10 - & gt; 4
345/100%10 - & gt; 3

CodePudding user response:

 using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
Using System. The Threading. The Tasks;

The namespace ConsoleApplication1
{
Class Program
{
The static void Main (string [] args)
{
List List=GetList (123456);
The foreach (int the number in the list)
{
Console. WriteLine (number);
}
}

The static List GetList (int number)
{
List List=new List (a);
While (number!=0)
{
List. The Add (number % 10);
Number=number/10;
}
List. The Reverse ();
Return the list;
}
}
}

CodePudding user response:

Directly to an integer to a string and then output each char

CodePudding user response:

refer to 6th floor OrdinaryCoder response:
directly to an integer to a string and then output each char


Ha ha this is master..

CodePudding user response:

refer to 7th floor by_ love reply:
Quote: refer to the sixth floor OrdinaryCoder response:

Directly to an integer to a string and then output each char


Ha ha this is master..

Don't need the whole special complex simple problem

CodePudding user response:

refer to the eighth floor OrdinaryCoder response:
Quote: refer to 7th floor by_ love reply:

Quote: refer to the sixth floor OrdinaryCoder response:

Directly to an integer to a string and then output each char


Ha ha this is master..

Simple question is not necessary to the whole of the special complex

Topic request said another recursive take over until more than the number is 0

CodePudding user response:

reference 4 floor Logerlink response:
345, for example

345/1%10 - & gt; 5
345/10%10 - & gt; 4
345/100%10 - & gt; 3
want positive sequence output, then how to deal with, need to use an array to operate

CodePudding user response:

references to the tenth floor PoemRan response:
Quote: refer to 4th floor Logerlink response:
345, for example

345/1%10 - & gt; 5
345/10%10 - & gt; 4
345/100%10 - & gt; 3
want positive sequence output, then how to deal with, need to use the array operation

An array Reverse Reverse to fix
  •  Tags:  
  • C#
  • Related