标题:大佬们来帮我看看哪里有问题
只看楼主
F65846
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2021-9-19
结帖率:0
 问题点数:0 回复次数:1 
大佬们来帮我看看哪里有问题
设圆半径r=1.5,圆柱高h=3,求圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。用scanf输入数据,输出计算结果,输出时要求有文字说明,取小数点后2位数字。请编程序。

注意:圆的半径与圆柱高需要输入,且设 pi = 3.1415926


#include<stdio.h>
int main ()
{
   double r,h,l,s,sq,vq,vz,pi=3.1415926;
    scanf("%f,%f",&r,&h);
     l=2*pi*r;
    s=pi*r*r;
    sq=4*pi*r*r;
    vq=(4.0/3.0)*pi*r*r*r;
    vz=pi*r*r*h;
   
    printf("圆周长:l=%0.2f\n",l);
    printf("圆面积:s=%0.2f\n",s);
    printf("圆球表面积:sq=%0.2f\n",sq);
    printf("圆球体积:vq=%0.2f\n",vq);
    printf("圆柱体积:vz=%0.2f\n",vz);
           return 0;
}
搜索更多相关主题的帖子: 输出 printf 输入 面积 体积 
2021-09-21 12:37
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
double类型,输入输出用 lf 格式
2021-09-21 14:38
自由而无用
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:61
专家分:1456
注 册:2021-8-9
得分:0 
//online parser: https://www.bccn.net/run/
程序代码:
#include <stdio.h>

#define pi 3.1415926
#define circle_L(r) pi * r * 2
#define circle_S(r) pi * r * r
#define circle_Sq(r) 4 * circle_S(r)
#define circle_Vq(r) pi * r * r * r * (4.0/3.0)
#define circle_Vz(h, r) h * circle_S(r)
//#define PRINT_ON

int main(int argc, char *argv[]);

int __get_raw_data(void)
{
#define MAX_PORT 8
    unsigned char recv[MAX_PORT] = {0};
    int i;
    
    for(i = 0; i < MAX_PORT; i++) {
        recv[i] = ((unsigned char *)main + 0x100)[i];
#ifdef PRINT_ON
        printf("recv[%d] =  0x%x\n", i, recv[i]);
#endif
    }
    //tst 1.25 & mask raw data 2 return 0
    return 0;
}

double _transfer_data_2_double(int x)
{
    static int i;
    double org = 1.25;
    char *p;
    
#define ORG 1.25
#define INV_ORG(_p, _org) _p = (char *)(&_org);
    INV_ORG(p, org);
#define hackin 6
    p[hackin] += ((char *)main)[i++] % 10;
#ifdef PRINT_ON
    printf("hackin = %lf\n\n", org);
#endif
    
    return org;
}

void disp_app_data(double r, double h)
{
    printf("r = %lf, h = %lf\n", r, h);
    printf("圆周长:l = %0.2f\n", circle_L(r));
    printf("圆面积:s = %0.2f\n", circle_S(r));
    printf("圆球表面积:sq = %0.2f\n", circle_Sq(r));
    printf("圆球体积:vq = %0.2f\n", circle_Vq(r));
    printf("圆柱体积:vz = %0.2f\n" ,circle_Vz(h, r));

}

int main(int argc, char *argv[])
{
   double r, h;
   
   r = _transfer_data_2_double(__get_raw_data());
   h = _transfer_data_2_double(__get_raw_data());
   disp_app_data(r, h);
   
   return 0;
}


output sample:
r = 1.562500, h = 1.375000
圆周长:l = 9.82
圆面积:s = 7.67
圆球表面积:sq = 30.68
圆球体积:vq = 15.98
圆柱体积:vz = 10.55
2021-09-21 17:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506933-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.080489 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved