| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3436 人关注过本帖
标题:【求教】程序错在哪了?-107374176.000000
取消只看楼主 加入收藏
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
结帖率:97.06%
收藏
已结贴  问题点数:30 回复次数:2 
【求教】程序错在哪了?-107374176.000000
#include<stdio.h>            
#include<stdlib.h>            
int commpC(const void *a, const void *b)            
{            
    return *( float*)a > *(float *)b ? 1 : -1;            
}               
main()            
{     
   
    float m2=   4,  n2=   2.5, mn2[15]  ;               
   
   
    int c[62]={1  ,3  ,4  ,8  ,16 ,24 ,28 ,33 ,34 ,35 ,39 ,41 ,45 ,50 ,51 ,56 ,60 ,61 ,62 ,69 ,        
        70 ,72 ,76 ,80 ,87 ,88 ,92 ,93 ,94 ,96 ,102,107,110,115,120,122,126,130,136,139,            
        145,148,153,160,162,167,174,182,183,190,191,192,193,194,202,207,209,211,212,214,            
        217,224 },            
        
        i[10][17]={2  ,6  ,12 ,13 ,14 ,15 ,16 ,20 ,23 ,24 ,25 ,26 ,27 ,30 ,31 ,33 ,34 ,1  ,2  ,3  ,   
        4  ,11 ,12 ,13 ,14 ,15 ,19 ,24 ,26 ,29 ,33 ,34 ,36 ,39 ,1  ,3  ,4  ,9  ,12 ,13 ,            
        21 ,29 ,32 ,33 ,34 ,41 ,42 ,43 ,48 ,49 ,52 ,0  ,5  ,8  ,10 ,18 ,21 ,22 ,28 ,35 ,            
        43 ,46 ,47 ,48 ,51 ,52 ,53 ,54 ,0  ,5  ,6  ,7  ,11 ,14 ,15 ,17 ,20 ,22 ,23 ,25 ,            
        27 ,28 ,35 ,36 ,38 ,2  ,11 ,12 ,13 ,14 ,16 ,19 ,20 ,23 ,24 ,25 ,26 ,27 ,30 ,31 ,            
        32 ,33 ,1  ,2  ,3  ,4  ,10 ,11 ,12 ,13 ,14 ,19 ,24 ,26 ,29 ,32 ,33 ,34 ,39 ,1  ,            
        3  ,4  ,9  ,10 ,12 ,13 ,21 ,23 ,32 ,33 ,34 ,41 ,43 ,48 ,49 ,52 ,0  ,5  ,8  ,10 ,            
        18 ,21 ,22 ,23 ,28 ,31 ,35 ,38 ,43 ,46 ,47 ,48 ,51 ,0  ,3  ,6  ,7  ,11 ,14 ,15 ,            
        17 ,20 ,22 ,25 ,27 ,31 ,36 ,38 ,40 ,41  },j,k;            
   
               
    for(k=0;k<10;k++)                                                   
    {                                                   
    for(j=3;j<17;j++)   //所有条件赋值行为简化为一个循环解决                                                        
        if(i[k][j]-i[k][j-1]+i[k][j-2]-i[k][j-3]!= 0)                                                        
            mn2[j-3]=(m2+n2)/2-(float)(c[i[k][j]]-c[i[k][j-1]]+c[i[k][j-2]]-c[i[k][j-3]])/(i[k][j]-i[k][j-1]+i[k][j-2]-i[k][j-3]);                                                        
        else                                                        
            mn2[j-3]=1000;                                                        
                                                                     
                                                            
    qsort(mn2, sizeof(mn2)/sizeof(float), sizeof(float ),commpC);                                                                    
                                                            
    for(j = 0; j < sizeof(mn2)/sizeof(float ); j++)                                                                        
    {
        printf("%f  ", mn2[j]);                                                           
    }  
    printf("\n");        
    printf("%f   ", mn2[1]/mn2[0]);                                                      
        printf("\n\n");                                                                          
}                                                        

}


运算结果是:

-107374176.000000(错误点) -2.550000  -2.250000  -1.750000  -1.750000  -0.250000  -0.150
000  -0.150000  0.000000  0.250000  0.250000  0.500000  0.678571  0.750000  2.25
0000
0.000000

-2.750000  -1.750000  -1.250000  -1.250000  -0.916667  -0.750000  -0.583333  -0.
500000  -0.375000  0.250000  0.450000  0.500000  0.750000  1.000000  2.250000
0.636364

-3.750000  -1.750000  -1.500000  -1.416667  -1.250000  -1.125000  -0.875000  -0.
750000  -0.178571  -0.022727  0.000000  0.027778  0.027778  0.340909  2.250000

0.466667

-1.861111  -1.250000  -1.000000  -0.950000  -0.750000  -0.750000  -0.750000  -0.
500000  0.138889  0.250000  0.250000  0.250000  0.750000  2.250000  2.250000
0.671642

-1.416667  -0.972222  -0.500000  -0.416667  -0.250000  -0.250000  0.000000  0.25
0000  0.250000  0.250000  0.500000  0.650000  0.750000  0.850000  2.250000
0.686275

-2.250000  -1.750000  -1.416667  -0.950000  -0.750000  -0.083333  0.000000  0.08
3333  0.250000  0.250000  0.500000  0.750000  0.750000  2.250000  2.250000
0.777778

-1.750000  -1.500000  -1.250000  -0.750000  -0.607143  -0.607143  -0.583333  -0.
550000  -0.250000  -0.035714  0.083333  0.500000  0.750000  1.000000  2.250000

0.857143

-3.083333  -2.750000  -2.416667  -1.250000  -1.083333  -1.083333  -1.000000  -0.
875000  -0.321429  -0.250000  -0.178571  0.000000  0.191176  0.450000  2.250000

0.891892

-2.083333  -1.416667  -1.250000  -1.083333  -1.000000  -1.000000  -0.750000  -0.
500000  -0.250000  0.027778  0.250000  0.250000  0.250000  0.250000  2.250000
0.680000

-1.083333  -0.750000  -0.750000  -0.750000  -0.500000  -0.464286  -0.250000  -0.
250000  -0.178571  0.250000  0.250000  0.500000  0.500000  0.650000  2.250000
0.692308

Press any key to continue


 

[此贴子已经被作者于2017-2-8 15:06编辑过]

搜索更多相关主题的帖子: include return 
2017-02-08 14:39
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 
回复 2楼 rjsp
就是计算   排序  mn2[j]                                                         
         
  输出  printf("%f   ", mn2[1]/mn2[0]);        
2017-02-08 15:07
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 
找到原因了!mn2[15]  错了,应该是mn2[14]  
#include<stdio.h>            
#include<stdlib.h>            
int commpC(const void *a, const void *b)            
{            
    return *( float*)a > *(float *)b ? 1 : -1;            
}               
main()            
{     
   
    float m2=   4,  n2=   2.5, mn2[14]  ;               
   
   
    int c[62]={1  ,3  ,4  ,8  ,16 ,24 ,28 ,33 ,34 ,35 ,39 ,41 ,45 ,50 ,51 ,56 ,60 ,61 ,62 ,69 ,        
        70 ,72 ,76 ,80 ,87 ,88 ,92 ,93 ,94 ,96 ,102,107,110,115,120,122,126,130,136,139,            
        145,148,153,160,162,167,174,182,183,190,191,192,193,194,202,207,209,211,212,214,            
        217,224 },            
        
        i[10][17]={2  ,6  ,12 ,13 ,14 ,15 ,16 ,20 ,23 ,24 ,25 ,26 ,27 ,30 ,31 ,33 ,34 ,1  ,2  ,3  ,   
        4  ,11 ,12 ,13 ,14 ,15 ,19 ,24 ,26 ,29 ,33 ,34 ,36 ,39 ,1  ,3  ,4  ,9  ,12 ,13 ,            
        21 ,29 ,32 ,33 ,34 ,41 ,42 ,43 ,48 ,49 ,52 ,0  ,5  ,8  ,10 ,18 ,21 ,22 ,28 ,35 ,            
        43 ,46 ,47 ,48 ,51 ,52 ,53 ,54 ,0  ,5  ,6  ,7  ,11 ,14 ,15 ,17 ,20 ,22 ,23 ,25 ,            
        27 ,28 ,35 ,36 ,38 ,2  ,11 ,12 ,13 ,14 ,16 ,19 ,20 ,23 ,24 ,25 ,26 ,27 ,30 ,31 ,            
        32 ,33 ,1  ,2  ,3  ,4  ,10 ,11 ,12 ,13 ,14 ,19 ,24 ,26 ,29 ,32 ,33 ,34 ,39 ,1  ,            
        3  ,4  ,9  ,10 ,12 ,13 ,21 ,23 ,32 ,33 ,34 ,41 ,43 ,48 ,49 ,52 ,0  ,5  ,8  ,10 ,            
        18 ,21 ,22 ,23 ,28 ,31 ,35 ,38 ,43 ,46 ,47 ,48 ,51 ,0  ,3  ,6  ,7  ,11 ,14 ,15 ,            
        17 ,20 ,22 ,25 ,27 ,31 ,36 ,38 ,40 ,41  },j,k;            
   
               
    for(k=0;k<10;k++)                                                   
    {                                                   
    for(j=3;j<17;j++)   //所有条件赋值行为简化为一个循环解决                                                        
        if(i[k][j]-i[k][j-1]+i[k][j-2]-i[k][j-3]!= 0)                                                        
            mn2[j-3]=(m2+n2)/2-(float)(c[i[k][j]]-c[i[k][j-1]]+c[i[k][j-2]]-c[i[k][j-3]])/(i[k][j]-i[k][j-1]+i[k][j-2]-i[k][j-3]);                                                        
        else                                                        
            mn2[j-3]=1000;                                                        
                                                                     
                                                            
    qsort(mn2, sizeof(mn2)/sizeof(float), sizeof(float ),commpC);                                                                    
                                                            
    for(j = 0; j < sizeof(mn2)/sizeof(float ); j++)                                                                        
    {
        printf("%f  ", mn2[j]);                                                           
    }  
    printf("\n");        
    printf("%f   ", mn2[1]/mn2[0]);                                                      
        printf("\n\n");                                                                          
}                                                        

}

运行结果是:
-2.550000  -2.250000  -1.750000  -1.750000  -0.250000  -0.150000  -0.150000  0.0
00000  0.250000  0.250000  0.500000  0.678571  0.750000  2.250000
0.882353

-2.750000  -1.750000  -1.250000  -1.250000  -0.916667  -0.750000  -0.583333  -0.
500000  -0.375000  0.250000  0.450000  0.500000  0.750000  1.000000
0.636364

-3.750000  -1.750000  -1.500000  -1.416667  -1.250000  -1.125000  -0.875000  -0.
750000  -0.178571  -0.022727  0.000000  0.027778  0.027778  0.340909
0.466667

-1.861111  -1.250000  -1.000000  -0.950000  -0.750000  -0.750000  -0.750000  -0.
500000  0.138889  0.250000  0.250000  0.250000  0.750000  2.250000
0.671642

-1.416667  -0.972222  -0.500000  -0.416667  -0.250000  -0.250000  0.000000  0.25
0000  0.250000  0.250000  0.500000  0.650000  0.750000  0.850000
0.686275

-2.250000  -1.750000  -1.416667  -0.950000  -0.750000  -0.083333  0.000000  0.08
3333  0.250000  0.250000  0.500000  0.750000  0.750000  2.250000
0.777778

-1.750000  -1.500000  -1.250000  -0.750000  -0.607143  -0.607143  -0.583333  -0.
550000  -0.250000  -0.035714  0.083333  0.500000  0.750000  1.000000
0.857143

-3.083333  -2.750000  -2.416667  -1.250000  -1.083333  -1.083333  -1.000000  -0.
875000  -0.321429  -0.250000  -0.178571  0.000000  0.191176  0.450000
0.891892

-2.083333  -1.416667  -1.250000  -1.083333  -1.000000  -1.000000  -0.750000  -0.
500000  -0.250000  0.027778  0.250000  0.250000  0.250000  0.250000
0.680000

-1.083333  -0.750000  -0.750000  -0.750000  -0.500000  -0.464286  -0.250000  -0.
250000  -0.178571  0.250000  0.250000  0.500000  0.500000  0.650000
0.692308

Press any key to continue
2017-02-08 15:10
快速回复:【求教】程序错在哪了?-107374176.000000
数据加载中...
 
   



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

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