C 语言程序设计——第一章课后编程题

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;
}
相关推荐
半壶清水1 天前
用python脚本加html自建的书法字典
开发语言·python·html
凯瑟琳.奥古斯特1 天前
力扣1003题C++解法详解
开发语言·c++·算法·leetcode·职场和发展
计算机安禾1 天前
【算法分析与设计】第48篇:流算法与数据概要技术
java·服务器·网络·数据库·算法
myenjoy_11 天前
Python + Snap7 实现西门子 S7-1200/1500 数据采集
开发语言·python
hunterkkk(c++)1 天前
SPFA最短路径算法(c++)
java·c++·算法
weixin_446260851 天前
HANDOFF:基于蒸馏互补教师的人形机器人任务空间整体控制
人工智能·算法·机器人
c238561 天前
C++11final与override6、智能指针
开发语言·c++
*neverGiveUp*1 天前
初步了解Django框架
开发语言·python·django
Java_2017_csdn1 天前
在 Java 中,MessageFormat.format() 和 String.format() 函数对比?
java·开发语言·前端·数据库
绛洞花主敏明1 天前
Go操作xorm中间表多对多关联实战
开发语言·后端·golang