gpt4 book ai didi

c - C 中的程序无法正确接收输入的问题

转载 作者:行者123 更新时间:2023-12-02 07:04:27 27 4
gpt4 key购买 nike

我对这个程序的输出有疑问。它没有正确接收输入。我相信这可能与我作为 scanf 的用户定义函数有关

#include <stdio.h>
#include <math.h>
#define PI 3.14


int GetNum(void)
{
return scanf("%d");
}

int CalculateAreaR(int length, int width)
{
return length*width;
}

double CalculateAreaC(int radius)
{
return PI*radius*radius;
}

int main(void)
{
int length;
int width;
int radius;
int areaR;
double areaC;

printf( " Please enter the length of a rectangle \n");
length = GetNum();
printf(" Please enter the width of a rectangle \n");
width = GetNum();
printf(" Please enter the radius of a circle \n");
radius = GetNum();

areaR = CalculateAreaR(length, width);

printf("\nThe area of the rectangle is %d\n", areaR);

printf("\nThe length is %d, the width is, %d and thus the area of the rectangle is %d\n\n", length, width, areaR);

areaC = CalculateAreaC(radius);

printf("\nThe area of the circle is %.3f\n", areaC);

printf("\n\n The radius of the circle is %d and the area of the circle is %.3f\n\n", radius, areaC);

return 0;
}

最佳答案

你可以尝试这样修改你的程序

int GetNum(void)
{
int num;
scanf("%d", &num);

return num;

关于c - C 中的程序无法正确接收输入的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14784543/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com