current position:Home>C language to find the volume and surface area of the ball, the volume is equal to the surface area?
C language to find the volume and surface area of the ball, the volume is equal to the surface area?
2022-02-04 16:42:11 【CSDN Q & A】
Error code :
#include<stdio.h>
#include<math.h>
int main()
{
const double PI = 3.14159;
double r, volume, surface_area;
printf("Please input the radius of the ball: ");
scanf("%lf", &r);
volume = 4PIpow(r,3)/3;
surface_area = 4PIpow(r,2);
printf("volume=%lf, surface_area=%lf", volume, surface_area);
}
Corrected :
#include<stdio.h>
#include<math.h>
int main()
{
const double PI = 3.14159;
double r, volume, surface_area;
printf("Please input the radius of the ball: ");
scanf("%lf", &r);
volume = 4/3PIpow(r,3);
surface_area = 4PIpow(r,2);
printf("volume=%lf, surface_area=%lf", volume, surface_area);
}
I don't understand !! Why? , Formula for volume /3 To put 4 The back is right ? and , Even if the volume formula is wrong , Why is the output equal to the area ?
Take the answer :
Did you post it upside down
If integer division .4/3=1, If one side of the division operation is a floating point number , As a floating point number , therefore /3 The position of the affects the result
Other answers 2:
volume = 4.0/3*PI*pow(r,3);
Other answers 3:
No problem , Revised as follows , For reference :
#include<stdio.h>#include<math.h>int main(){ const double PI = 3.14159; double r, volume, surface_area; printf("Please input the radius of the ball: "); scanf("%lf", &r); volume = 4.0 * PI * pow(r, 3) / 3; //volume = 4.0 / 3 * PI * pow(r, 3); surface_area = 4.0 * PI * pow(r, 2); printf("volume=%lf, surface_area=%lf", volume, surface_area); return 0;}
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041642091904.html
The sidebar is recommended
- What is the cost description of configuring data integration tasks between RDS and MySQL?
- What are the steps to configure the data integration task between RDS and MySQL?
- What are the data skew phenomena in MapReduce?
- What is the impact of stopping data integration tasks in DTS?
- What is the difference between quick Bi and power Bi in data source connection?
- What is the implementation principle of the four features of MySQL transactions?
- What is the impact of restoring data integration tasks in DTS?
- What are the fault tolerance methods in spark?
- What is the impact of deleting data integration tasks in DTS?
- What are the implementation ideas of transaction acid feature of MySQL?
guess what you like
-
What is the difference between quick Bi and power Bi in data processing and modeling?
-
What are the operational steps for managing data integration tasks in DTS?
-
What are the five advantages of spark?
-
What are the operation steps of modifying scheduling policy in DTS?
-
What are the similarities and differences between MapReduce and spark?
-
What are the differences between quick Bi and power Bi in visual presentation and report making?
-
How does MapReduce specify the number of CPUs at runtime?
-
How to write SQL to effectively use composite index?
-
What is the difference between quick Bi and power Bi on the mobile end?
-
How does MapReduce specify the size of runtime memory?
Random recommended
- What is the explanation of the scheduling policy in DTS?
- What are the instructions for modifying the scheduling effective date in DTS?
- What are the instructions for modifying the scheduling cycle in DTS?
- What are the streaming data writing functions in maxcompute?
- What will happen to the database self incrementing primary key?
- How does MapReduce tune the operating system?
- What are the performance advantages of streaming data writing in maxcompute?
- What is the description of modifying the task failure policy in DTS?
- How does MySQL master-slave replication work?
- What is the technical architecture of streaming data writing in maxcompute?
- What is the background information of monitoring alarm configured in DTS?
- What are the reasons for the delay of master-slave synchronization in MySQL?
- What are the operation steps for configuring monitoring alarms in DTS?
- Server in zookeeper A = B: C: D what do they mean?
- What is the query acceleration function in maxcompute?
- What is the solution to the master-slave synchronization delay of MySQL?
- What parameters are frequently adjusted when running MapReduce tasks?
- What is the technical architecture of query acceleration in maxcompute?
- What are the operation steps of viewing historical tasks in DTS?
- In 2020, Alibaba Android classic: after getting the offer, Alibaba fished up the resume again
- Summary of common knowledge points of Android interview in 2020, HashMap traversal
- 2020android will never die. As a programmer, what do you think is the biggest sorrow
- Linux system programming 43 file descriptor
- C + + date judgment blank filling is required to complete the blank filling
- About the parameter problem in Ajax, geigei help
- The number of daffodils in C language is wrong,
- UE4 carving terrain painting display problem
- Single chip C51 assembly language scatter program error
- Hello, let me ask Prometheus how to write port rules
- How can Linux ssh server solve the following problems
- (i++)+(--i)
- How about the Java debug mode? This is what I finally appeared.
- Linux operating system, online solution
- Calculate the value of the formula and display it on the screen
- What is the use of inter address access pointer access reference access
- There are two different pages in the front end. Add data on one page and refresh the data on the other page
- Find someone to teach me how to train somethingv2 on slowfast
- How can the statistics after pandas group by be output conditionally?
- Nlogit import data, whether in CSV or exclude format, not even the CSV format exported by Stata. Project import cannot import it
- Problems and solutions in the research and implementation of monitoring system testing in Universities Based on Servlet