C 语言程序设计------第一章课后编程题
第四题:编写一个 C 程序,运行时输出 Hello World!
c
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
第五题:运行输出图形
- 方法一(不推荐):暴力输出。缺点:数量很大后麻烦
c
#include <stdio.h>
int main() {
printf("*****\n");
printf(" *****\n");
printf(" *****\n");
printf(" *****\n");
return 0;
}
- 方法二
c
#include <stdio.h>
int main() {
int n = 4; // 行数
int num = 5; // * 数
for (int i = 0; i < n; i++) {
for (int temp = i * 2; temp; temp--) // temp 计算打印空格数
printf(" ");
for (int j = 0; j < num; j++) // 打印 * 数
printf("*");
printf("\n"); // 打印完一行后换行
}
return 0;
}
第六题:运行时输入 a, b, c 三个值,输出最大值
c
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a > b) {
if (a > c)
printf("%d\n", a);
else
printf("%d\n", c);
} else {
if (b > c)
printf("%d\n", b);
else
printf("%d\n", c);
}
return 0;
}