C#程序输出1-99之间,不能被 3整除,且不带"3"的所有整数.如:1,2,4,5,7……11,14,16?
问题描述:
C#程序输出1-99之间,不能被 3整除,且不带"3"的所有整数.如:1,2,4,5,7……11,14,16??有没有适合新手的的解决方式啊,谢谢
答
using System;
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
for (int i = 1; i <= 99; i++)
{
if (i.ToString().IndexOf("3") != -1 || i % 3 == 0) continue;
Console.WriteLine(i);
}
}
}
}
1
2
4
5
7
8
10
11
14
16
17
19
20
22
25
26
28
29
40
41
44
46
47
49
50
52
55
56
58
59
61
62
64
65
67
68
70
71
74
76
77
79
80
82
85
86
88
89
91
92
94
95
97
98
问题解决请点下"采纳"
答
n/3==0||n%10==3||n/10==3
n/3 n被3整除
n%10==3 n对10取余为3 也就是,个位是3
n/10==3 十位是3
for循环判断