谁能帮忙看下这个代码是哪儿错了为什么完全得不到想要的结果????
就连第一个函数N1=[a/2][b/2]得到的结果也不对??[a/2][b/2]代表两个数除以2取整相乘得到整数。程序代码:
#include<stdio.h> #include<math.h> int no1(double a,double b); int no2(double a,double b); int no3(double a,double b); main(){ double a,b; printf("请输入矩形的长和宽:\n"); scanf("%lf,%lf\n",&a,&b); printf("方案一可获得圆盘个数为:%d\n",no1(a,b)); printf("方案二可获得圆盘个数为:%d\n",no2(a,b)); if(a==b) printf("方案三可获得圆盘个数为:%d\n",no3(a,b)); } int no1(double a,double b){ int n1; n1=(int)floor(a/2.0)*floor(b/2.0); return n1; } int no2(double a,double b){ int n2,m; m=(int)floor((a-2)/pow(3,0.5))+1; if((int)floor(b)/2==0&&m%2!=0) n2=m*(floor(b)-1)/2+1/2; if(m%2==0) n2=m*(floor(b)-1)/2; return n2; } int no3(double a,double b){ int n3,n31,n32,m1; double b1; b1=floor((3/10)*a); n31=floor(a/2)*floor(b1/2); m1=(int)floor((a-2)/pow(3,0.5))+1; if(floor(a)/2==0) n32=m1*(floor(a)-1)/2+1/2; else n32=m1*(floor(a)-1)/2; n3=n31+n32-floor(a); return n3; }