程序设计与算法(一)第二周测验(2017夏季) 解题报告

来源:互联网 发布:成都房地产大数据分析 编辑:程序博客网 时间:2024/05/16 19:33

a 对齐输出

#include <stdio.h>int main(){    int a,b,c;    while (~scanf("%d%d%d",&a,&b,&c)){        printf("%8d %8d %8d\n",a,b,c);    }    return 0;}

b 输出保留12位小数的浮点数

#include <stdio.h>int main(){    double x;    while (~scanf("%lf",&x)){        printf("%.12f",x);    }    return 0;}

c 空格分隔输出

#include <iostream>#include <stdio.h>using namespace std;int main(){    char a;    int b;    float c;    double d;    cin>>a>>b>>c>>d;    printf("%c %d %f %f\n",a,b,c,d);    return 0;}

d 计算球的体积

#include <stdio.h>#include <iostream>using namespace std;int main(){    double r;    while (cin>>r){        double ans=4.0/3*r*r*r*3.14;        printf("%.2f",ans);    }    return 0;}

e 大象喝水

#include <stdio.h>#include <iostream>using namespace std;#define Pi 3.14159int main(){    double h,r;    while (cin>>h>>r){        double ans=Pi * r * r * h;        int k = 20*1000/ans;        if (20*1000-ans*k>1e-6) k++;        cout<<k<<endl;    }    return 0;}
阅读全文
0 0
原创粉丝点击