Lecture (2)包含一下五道编程题,可以在上面的OJ提交。
007:对齐输出
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%8d %8d %8d\n",a,b,c);
return 0;
}
008:输出保留12位小数的浮点数
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
double f;
scanf("%lf",&f);
printf("%.12lf\n",f);
return 0;
}
009:空格分隔输出
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
char c;
int a;
float f;
double d;
scanf("%c%d%f%lf",&c,&a,&f,&d);
printf("%c %d %.6f %.6lf\n",c,a,f,d);
return 0;
}
010:计算球的体积
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
double r;
scanf("%lf",&r);
double v;
v = 3.14*r*r*r*(4/3.0);
printf("%.2lf\n",v);
return 0;
}
011:大象喝水
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, const char * argv[]) {
int h,r;
scanf("%d%d",&h,&r);
double v;
v = 3.14159*r*r*h;
int count;
count = ceil(20*1000/v); \\ceil对浮点数 向上取整
printf("%d\n",count);
return 0;
}