You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用基础C语言实现按百分比打印控制台圆形(无图形库)

问题:实现打印圆形的指定百分比部分(基础C语言)

我已经编写了一个可根据用户输入的直径在控制台打印圆形的C程序,现在希望修改程序,使其仅打印圆形的指定百分比部分,预期效果为只显示圆形的某一扇形区域(比如按输入百分比对应的角度范围展示)。

注:这是作业任务,仅允许使用基础C语言,不得使用指针、外部库等特性。我搜索解决方案近2小时仍无头绪,恳请帮助。

以下是我已完成的初始程序:

#include <stdio.h>

/**
 * @brief Prints the header to the console
 */
void printHeader() {
    printf("Ausgabe Teilaufgabe 5.2.1\n");
}

/**
 * @brief Get the Durchmesser from the user via console input
 * 
 * @return int (Durchmesser)
 */
int getDurchmesser() {
    int d = 0;
    printf("Bitte Durchmesser des Kreises eingeben: ");
    scanf("%d", &d);
    getchar();
    return d;
}

/**
 * @brief Prints a circle out of "*" to the console with a given diameter
 * 
 * @param d (Durchmesser)
 */
void printCircle(int d) {
    for(int i= -d; i < d; i++) {
        for(int j = -d; j < d; j++) {
            if(i*i + j*j < d*d) {
                printf("*");
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }
}

/**
 * @brief Starting point of the program
 * 
 * @return int (Success Code)
 */
int main() {
    printHeader();
    int d = getDurchmesser();
    printCircle(d);
    return 0;
}

内容的提问来源于stack exchange,提问作者Solon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 00:45:40