1.关于圆的计算
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
int main() {
float r, h, l, s, ss, v, vv;
scanf_s("%f %f", &r, &h);
l = 2 * PI * r;
s = PI * pow(r, 2);
ss = 4 * PI * pow(r, 2);
v = PI * pow(r, 3) * 4 / 3;
vv = s * h;
printf("l=%.2f\n", l);
printf("s=%.2f\n", s);
printf("ss=%.2f\n", ss);
printf("v=%.2f\n", v);
printf("vv=%.2f", vv);
return 0;
}
2.课程成绩处理
#include <stdio.h>
int main() {
float score1, score2, score3, score4, sum, avg;
scanf_s("%f,%f,%f,%f", &score1, &score2, &score3, &score4);
sum = score1 + score2 + score3 + score4;
avg = sum / 4;
printf("sum=%.0f;average=%.2f", sum, avg);
return 0;
}
3.编程:小商店买糖计算
#include <stdio.h>
int main() {
float price1, price2, price3, kg1, kg2, kg3, money;
float sum, left;
scanf_s("%f %f %f %f", &kg1, &kg2, &kg3, &money);
price1 = 12.5;
price2 = 15.7;
price3 = 8.5;
sum = kg1 * price1 + kg2 * price2 + kg3 * price3;
left = money - sum;
printf("sum=%.2f\nleft=%.2f", sum, left);
return 0;
}
4.按要求输出下列结果
#include <stdio.h>
int main() {
int a, b, c;
double x, y, z;
long int u, n;
char c1, c2;
a = 3, b = 4, c = 5;
x = 1.2, y = 2.4, z = -3.6;
u = 51274, n = 128765;
c1 = 'a', c2 = 'b';
printf("a= %d b= %d c= %d\n", a, b, c);
printf("x=%.6lf,y=%.6lf,z=%.6lf\n", x, y, z);
printf("x+y= %.2lf y+z=%.2lf z+x=%.2lf\n", x + y, y + z, z + x);
printf("u= %ld n= %ld\n", u, n);
printf("c1='%c' or %d(ASCII)\n", c1,c1);
printf("c2='%c' or %d(ASCII)", c2, c2);
return 0;
}
5.国民生产总值计算
#include <stdio.h>
#include <math.h>
int main() {
float r, p, n;
scanf_s("%f %f", &r, &n);
p = (pow(1 + r, n) - 1) * 100;
printf("%.1f", p);
return 0;
}