判断1000到2000之间的闰年

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//  能4整除不能被100整除,能被400整除
#include <stdio.h>
int main()
{
int i;
int j;
int count=0;
for (i = 1000; i < 2000; i++)
{
if (i % 4 == 0)
{
if (i % 100 != 0)
{
printf("%d ", i);
count++;
}
}
if (i % 400 == 0)
{
printf("%d ", i);
count++;
}
if (count >= 8)
{
count = 0;
printf("\n");
}
}

system("pause");
return 0;
}

输出乘法口诀表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
int main()
{
int i;
int j;
for (i = 1; i <= 9; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d*%d = %d ",i,j,i*j);
}
printf("\n");
}
system("pause");
return 0;
}

计算100到200之间的素数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//素数只能被1和他本身整除
#include <stdio.h>
#include <math.h>
int main()
{
int i;
int j;

for (i = 101; i < 200;i+=2)
{
for (j = 2; j <= sqrt(i); j++)
{
if (i%j == 0){ break; }
}
if (j >sqrt(i))
{
printf("%d \n", i);
}
}
system("pause");
return 0;
}