写代码将三个整数数按从大到小输出
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
int main()
{
int a = 0;
int b = 0;
int c = 0;
int t = 0;
scanf("%d %d %d", &a, &b, &c);
if (a < b)
{
t = a;
a = b;
b = t;
}
if (a < c)
{
t = a;
a = c;
c = t;
}
if (b < c)
{
t = b;
b = c;
c = t;
}
printf("%d %d %d\n", a, b, c);

return 0;
}
打印3的倍数的数
1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
int a = 0;
int b = 0;
for(int i = 1;i <= 100; i++)
{
if(i % 3 == 0)
{
printf("%d ",i);
}
}
return 0;
}
最大公约数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main()
{
int a = 0;
int b = 0;
int c = 0;
scanf("%d %d", &a, &b);
if(a < b)//确保 a<=b
{
c = a;
a = b;
b = c;
}
while(b != 0)
{
c = a % b;
a = b;
b = c;
}
printf("%d", a);

return 0;
}

打印闰年

1
2
3
4
5
6
7
8
9
int main()
{
for (int a = 1000; a <= 2000; a++)
{
if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
printf("%d ", a);
}
return 0;
}

打印素数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main()
{
int a = 0;
int i = 0;
for (a = 100; a <= 200; a++)
{
for (i = 2; i < a; i++)
{
if (a % i == 0)
{
break;
}
}
if(a==i)
{
printf("%d ", a);
}
}
return 0;
}

数9的个数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
int a;
int i = 0;
for (a = 0; a <= 100; a++)
{
if (a % 10 == 9)
{
i++;
}
if (a / 10 == 9)
{
i++;
}
}
printf("%d", i);
return 0;
}

分数求和

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
double a = 0.0, b = 0.0,c = 0.0;
for (int i = 1; i <= 100; i += 2)
{
a = a + (1.0) / i;
}
for (int i = 2; i <= 100; i += 2)
{
b = b + (1.0) / i;
}
c = a - b;
printf("%lf", c);
return 0;
}

求最大值

乘法口诀表