去0輸出
把任意一個(gè)數(shù),去0輸出。比如輸入50408,輸出548;
? ? ? ? ? ? int n = Convert.ToInt32(Console.ReadLine());
? ? ? ? ? ? int sum = 0;
? ? ? ? ? ? int cheng = 1;
? ? ? ? ? ? while (n != 0)//5126
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int i = n % 10;
? ? ? ? ? ? ? ? if (i != 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? i *= cheng;
? ? ? ? ? ? ? ? ? ? sum += i;
? ? ? ? ? ? ? ? ? ? cheng *= 10;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? n /= 10;?
? ? ? ? ? ? }
? ? ? ? ? ? Console.WriteLine(sum);
標(biāo)簽: