编写函数
编写已知半径求面积的函数,供主函数调用。要求在主函数中输入10个半径值,对于给定的半径值,判别其否大于0,若大于,则输出对应的面积。
这是我打的,打到一半不知道该怎么办了。。。。求助求助
#include<stdio.h>
#define Π 3.14
int s()
{
int r, square;
printf("请输入半径:\n");
scanf("%d", &r);
square = Π * r * r;
return 0;
}
int main(void)
{
int a = { 0 };
} #include <stdio.h>
#define pi 3.14159
#define area(r) r*r*pi
int main() {
int nums = {0}, r;
for(size_t n = 0, m = 0; n < 10; n++) {
scanf("%d", &r);
if(r > 0) nums = area(r);
}
for(size_t n = 0; nums; n++)
printf("%d ", nums);
return 0;
} 本帖最后由 jackz007 于 2021-12-10 00:03 编辑
#include <stdio.h>
#define PI 3.14159265358979323846
double s(double r)
{
return (r > 0.0) ? r * r * PI : 0.0 ;
}
int main(void)
{
double r ;
int i ;
for(i = 0 ; i < 10 ; i ++) scanf("%lf" , & r) ;
for(i = 0 ; i < 10 ; i ++) {
if(r > 0) {
printf("r = %lf , s = %lf\n" , r , s(r)) ;
}
}
}
编译、运行实况:
D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
1 2 3 4 5 6 7 8 9 10
r = 1.000000 , s = 3.141593
r = 2.000000 , s = 12.566371
r = 3.000000 , s = 28.274334
r = 4.000000 , s = 50.265482
r = 5.000000 , s = 78.539816
r = 6.000000 , s = 113.097336
r = 7.000000 , s = 153.938040
r = 8.000000 , s = 201.061930
r = 9.000000 , s = 254.469005
r = 10.000000 , s = 314.159265
D:\00.Excise\C> jackz007 发表于 2021-12-10 00:01
编译、运行实况:
三克油
页:
[1]