|
设蛋糕的半径是R,则求出弦长的单位是R。参考代码如下——
#include "stdio.h"
#include "math.h"
int main(int argc,char *argv[]){
double zt,x,y,t,pai=3.1415926535897932,e=1E-6;
printf("Please enter the x & y(R:x,y>=0)...\n");
if(scanf("%lf%lf",&x,&y)!=2 || x<0 || y<0 || x+y==0){
printf("Input error, exit...\n");
return 0;
}
t=pai/(x+y)*(x>y ? y : x);
for(zt=0;fabs(0.5*zt-sin(zt/2)*sqrt(1-sin(zt/2))-t)>e;zt+=e);
printf("The chord length is %.2fR\n",2*sin(zt/2));
return 0;
}
代码格式和运行样例图片: