解题思路:输入圆半径(),输出面积,保留两位小数
注意事项: 1、首先作为初学的自我提醒吧:
输入的&不能少!!!
语句末尾;不能少!!!
2、半径是浮点类型。
定义变量时int(占2个或4个字节)是整型,flout(单精度,4个字节)和double(双精度,8个字节)是浮点型。
与之对应的,输入半径以及输出面积时注意:整型对应“%d”,浮点型对应“%f”。
但输入和输出不一定是同一种类型,例如输入半径是整数,输出面积是三位小数:
int r; float s; scanf("%d",&r); printf("%0.3f",s);
当然,这里仅仅是为了说明定义和输入输出的对应问题,省略了很多要素。
3、输出保留两位小数。
“0.2f”
参考代码:
#include<stdio.h> int main() { float r,s; scanf("%f",&r); s=r*r*3.1415; printf("%0.2f",s); return 0; }
0.0分
28 人评分
#include<stdio.h> #define PI 3.14159 int main() { float S,R; scanf("%f",&R); S=R*R*PI; printf("%0.2f\n",S); return 0; }
#include<stdio.h> int main() { float r,S; printf("请输入半径:"); scanf("%f",&r); S=r*r*3.14; printf("面积为%.2f\n",S); return 0; } 这错在哪了
#include <stdio.h> #define Π 3.1415926 #include <math.h> int main() { float r,s; scanf("%f",&r); s = Π * pow(r,2); printf("%.2f", s); return 0; } 直接显示编程错误,但是在VS里就没问题……
水光风火 2024-02-05 17:42:09 |
不是英文,肯定识别不了!!!
#include<stdio.h> #define P 3.1415 int main() { int r = 0; float c = 0; scanf("%d", &r); c = P * r * r; printf("%0.2f\n", c); return 0; } 不晓得哪里有问题,只显示对一半
TheMagician 2023-12-10 01:21:53 |
输入的圆半径是浮点数,你的r是整形
#include<stdio.h> int main() { double r,S; S=r*r*3.1415; scanf("%lf",&r); printf("%.2lf\n",S); return 0; } 大佬们看一下,输出为什么都是0.00啊
TheMagician 2023-12-10 01:25:00 |
scanf函数在S被赋值一句的下面,导致S被赋值时,S,r都没有被赋值。
#include<stdio.h> int main() { int a; float b; scanf("%f",&a); b=3.1415*a*a; printf("%0.2f",b); return 0; } 哪里有问题呢 -~-
小碗吃饭 2023-09-15 23:06:59 |
int是整型,scanf怎么用%f呢
#include<stdio.h> int main(void) { double a; while(scanf("%lf",&a)!=EOF){ double b; b=3.1415*a*a; printf("%.2lf\n",b); } return 0; } 服了,就因为我Π取得3.14,一直报错,我还以为哪里语法啥的错了,结果。。。。,长记性了,哈哈哈
zhu 2023-09-25 19:14:58 |
笑死,俺也一样,直接给他换成3.141592653
#include<stdio.h> int main() { double c,f; scanf("%lf",&f); c=3.141592*pow(f,2); printf("c=%0.2lf",c); return 0; } 为什么错了?