苏小红版第四版C语言程序设计,第三章习题
//3.2
/*
#include<stdio.h>
#include<math.h>
int main(void)
{
int a, b, c, x,y;
printf("Please input a munber:");
scanf("%d", &x);
x = (int)fabs(x); //得x的绝对值
a = x / 100; //计算百位数
b = (x - a*100) / 10; //计算十位数
c = x % 10; //计算个位数
y = c * 100 + b * 10 + a;
printf("%d", y);
return 0;
}
*/
/*
//3.3
#include<stdio.h>
#include<math.h>
int main(void)
{
int n;
double rate = 0.025;
double capital,deposit;
printf("Please input capital and n:");
scanf("%lf,%d", &capital, &n);
deposit = (1 + rate) * capital; //计算本金和利息之和
printf("%lf", deposit);
return 0;
}
*/
/*
//3.4
#include<stdio.h>
#include<math.h>
int main(void)
{
float a, b, c, disc, p, q;
printf("Please enter the coefficients a,b,c:");
scanf("%f,%f,%f", &a, &b, &c);
disc = b * b - 4 * a * c;
p = -b / (2 * a);
q = sqrt(disc) / (2 * a);
printf("x1=%7.4f,x2=%7.4f\n", p + q, p - q);
return 0;
}
*/
//3,5
#include<stdio.h>
#include<math.h>
int main(void)
{
const double pi = 3.14;
int r;
double s, v;
printf("Please input r:");
scanf("%d", &r);
s = 4 * pi * r * r;
v = 4 / 3 * pi * r * r * r;
printf("s=%0.2f,v=%0.2f", s, v);
return 0;
}