九九乘法表:
//九九乘法表 for (int x = 1; x < 10; x++) { for (int y = 1; y <=x;y++ ) { Console.Write(y.ToString()+"*"+x.ToString()+"="+(x*y).ToString()+" "); } Console.Write("\n"); } Console.ReadLine();
被七整除:
int i = 0; Console.Write("请输入一个数"); int n = Convert.ToInt32(Console.ReadLine()); for (int num = 7; num < n; num++) { if (num % 7 == 0) { Console.Write(num.ToString() + " "); i++; } } Console.Write("\n"); Console.Write("以上为"+n+"以内被7整除的数" + "\n" + "个数:" + i.ToString()); Console.ReadLine();
水仙花数:
int a, b, c; int n = 0; for (int num = 100; num < 1000;num++ ) { a = Convert.ToInt16(num/100); b = Convert.ToInt16(num/10-a*10); c = Convert.ToInt16(num-(a*100+b*10)); if (n == a * a * a + b * b * b + c * c * c) { Console.Write(num.ToString() + " "); n++; } } Console.WriteLine(); Console.Write("水仙花数的个数为" + n.ToString()); Console.ReadLine();