【专题】取得一个数各个位的值
class Program { static void Main(string[] args) { /* int i = 365; //就是三位数 int sheng = 365; int ge = sheng % 10; // int ge = i % 10; Console.WriteLine("个位"+ge); //int sheng = i / 10;//36 sheng = sheng / 10; Console.WriteLine("剩" + sheng); int shi = sheng % 10; Console.WriteLine("十位" + shi); sheng = sheng / 10; Console.WriteLine("剩" + sheng); int bai = sheng % 10; Console.WriteLine("百位"+bai); sheng = sheng / 10; Console.WriteLine("剩" + sheng); */ /* int n = 3721886; int sheng = n; while (sheng != 0) { int wei = sheng % 10; Console.WriteLine(wei); sheng = sheng / 10; }*/ int n = 3721886; string s = n.ToString();//项目中哪个方便用哪个。面试的时候尽量不用.net内置的方法 for (int i = 0; i < s.Length; i++) { char ch = s[i]; int iWei = ch-'0';//'1'→1 //Console.WriteLine(ch); Console.WriteLine(iWei); } Console.ReadKey(); } }