| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 475 人关注过本帖
标题:谁能帮忙看下这个代码是哪儿错了为什么完全得不到想要的结果????
取消只看楼主 加入收藏
cquwt
Rank: 1
等 级:新手上路
帖 子:41
专家分:2
注 册:2013-12-24
结帖率:69.23%
收藏
已结贴  问题点数:5 回复次数:0 
谁能帮忙看下这个代码是哪儿错了为什么完全得不到想要的结果????
就连第一个函数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;
}
搜索更多相关主题的帖子: color 
2014-09-18 23:48
快速回复:谁能帮忙看下这个代码是哪儿错了为什么完全得不到想要的结果????
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012348 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved