1
2
3
4
5
6
7
8
#include <stdio.h>
int main() {
printf("\\ /\n");
printf(" \\/\n");
printf(" /\\\n");
printf("/ \\\n");
return 0;
}

2 学号

1
2
3
4
5
6
7
#include<stdio.h>
int main () {
char s[20];
scanf("%s", s);
printf("20%c%c", s[0], s[1]);
return 0;
}

3 平均数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;

int main() {
double a, b, c, d, n, z;
cin >> a >> b >> c >> d;
z = (a * 2.0 + b * 3.0 + c * 4.0 + d) / 10.0;
cout << "Media: " << z << endl;
if (z >= 7.0)
cout << "Aluno aprovado." << endl;
else if (z < 5.0)
cout << "Aluno reprovado." << endl;
else if (z < 7.0 && z >= 5.0) {
cout << "Aluno em exame." << endl;
}
}

4 质数

所有人必须掌握:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>

int isPrime(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0)
return 0;
return x > 1;
}

int main() {
int n;
scanf("%d", &n);
while(n--) {
int x;
scanf("%d", &x);
if (isPrime(x)) {
printf("%d is prime\n", x);
} else {
printf("%d is not prime\n", x);
}
}
return 0;
}

有能力的可以学习这个:

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
#include <stdio.h>
#define N 1000005
int isPrime[N + 1];

int main() {
int n;
scanf("%d", &n);
for (int i = 0; i <= N; i++)
isPrime[i] = 1;
isPrime[0] = isPrime[1] = 0;
for (int i = 2; i <= N; i++) {
for (int j = 2 * i; j <= N; j += i)
isPrime[j] = 0;
}
while(n--) {
int x;
scanf("%d", &x);
if (isPrime[x]) {
printf("%d is prime\n", x);
} else {
printf("%d is not prime\n", x);
}
}
return 0;
}

5 斐波那契数列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<stdio.h>

int main () {
int a[100];
a[1] = 1;
a[2] = 1;
int n;
scanf("%d", &n);
for (int i = 3; i <= n; i++)
a[i] = a[i - 1] + a[i - 2];
for (int i = 1; i <= n; i++)
printf("%d ", a[i]);
return 0;
}