# include <stdio.h>
# include <stdlib.h>
# define PI 3.14159
int main(void)
{
double r, c, s1, s2, v;
printf("輸入圓的半徑:\n\a");
scanf("%lf", &r);//這裡有變動,雙精度浮點型(double)輸入是用%lf
c = PI * 2.0 * r;
s1 = PI * r * r;
s2 = 4.0 * s1;
v = (4 * PI * r * r * r)/3.0;
printf("周長 = %lf\n圓面積 = %lf\n球面積 = %lf\n球體積 = %lf\n", c, s1, s2, v);
return 0;
}
想保留最後兩位:可以這樣
scanf("%lf", &r);//這裡有變動,雙精度浮點型(double)輸入是用%lf動 ,%.2lf
printf("周長 = %.2lf\n圓面積 = %.2lf\n球面積 = %.2lf\n球體積 = %.2lf\n", c, s1, s2, v);//這裡改動了,看看%.2lf
# include <stdio.h>
# include <stdlib.h>
# define PI 3.14159
int main(void)
{
double r, c, s1, s2, v;
printf("輸入圓的半徑:\n\a");
scanf("%lf", &r);//這裡有變動,雙精度浮點型(double)輸入是用%lf
c = PI * 2.0 * r;
s1 = PI * r * r;
s2 = 4.0 * s1;
v = (4 * PI * r * r * r)/3.0;
printf("周長 = %lf\n圓面積 = %lf\n球面積 = %lf\n球體積 = %lf\n", c, s1, s2, v);
return 0;
}
想保留最後兩位:可以這樣
# include <stdio.h>
# include <stdlib.h>
# define PI 3.14159
int main(void)
{
double r, c, s1, s2, v;
printf("輸入圓的半徑:\n\a");
scanf("%lf", &r);//這裡有變動,雙精度浮點型(double)輸入是用%lf動 ,%.2lf
c = PI * 2.0 * r;
s1 = PI * r * r;
s2 = 4.0 * s1;
v = (4 * PI * r * r * r)/3.0;
printf("周長 = %.2lf\n圓面積 = %.2lf\n球面積 = %.2lf\n球體積 = %.2lf\n", c, s1, s2, v);//這裡改動了,看看%.2lf
return 0;
}