①男人女人孩子先令问题
代码语言:javascript复制#include <stdio.h>
int main() {
int x, y, z;
for (x = 0; x <= 30; x ) //遍历全部
for (y = 0; y <= 30; y ) //遍历全部
for (z = 0; z <= 30; z ) //遍历全部
if (3 * x 2 * y z == 50 && x y z == 30) //判断语句
printf("%d,%d,%dn", x, y, z);
return 0;
}
②读取学生成绩,并且输出最大值
代码语言:javascript复制#include <stdio.h>
int main() {
int score, i, max;
max = 0;
for (i = 0; i <= 10; i ) {
scanf("%d", &score);
if (score > max) //判断语句
max = score;
}
printf("%d", max);
return 0;
}
③1! ..... 100!出现内存溢出,使用long long的for循环的实现.
代码语言:javascript复制#include <stdio.h>
int main() {
long long item, i, j;
long long sum = 0;
for (i = 1; i <= 100; i ) {
item = 1;
for (j = 1; j <= i; j ) {
item = item * j;
}
sum = sum item;
}
printf("%lld", sum);
return 0;
}
④一夫一妻问题?
代码语言:javascript复制#include <stdio.h>
int main() {
char i, j, k;
for (i = 'X'; i <= 'Z'; i )
for (j = 'X'; j <= 'Z'; j )
for (k = 'X'; k <= 'Z'; k )
if (i != j && i != k && j != k) {
if (i != 'X' && k != 'X' && k != 'Z')
printf("A--%c,B--%c,C--%c", i, j, k);
}
return 0;
}