| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1879 人关注过本帖
标题:求教,这个程序为什么计算错误?
只看楼主 加入收藏
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
结帖率:97.06%
收藏
 问题点数:0 回复次数:3 
求教,这个程序为什么计算错误?
  #include<stdio.h>        
    #include<math.h>        
    void main()        
    {        
            int i,j,k;

double a1[3]={1,2,3    },a2[10][3]={{2,3,4},{3,4,5},{4,5,6},{7,8,9},{10,11,12},{13,14,15},{16,17,18},{19,20,21},{22,23,24},{25,26,27}};            

 double D0[10],D1[10],D2[10],D3[10],D4[10],D5[10],D6[10],D7[10],D8=0,D9=0,D10=0,D11=0,D12=0,h,l,t;            
for(i=0;i<10;i++)            
    {        
        D0[i]=fabs(a1[3]-a2[i][3]);  D1[i]=fabs(a1[3]-a2[i][3]);   
    }        
for(i=0;i<10;i++)        
    {   
    D8+=D0[i];   
    }   
for(i=0;i<10;i++)        
{        
printf("%lf\n ",D0[i]);        
}        
    printf("\n");   

for(i=0;i<10-1;i++)        
for(j=i+1;j<10;j++)        
{        
    if(D1[i]>D1[j])   
    {   
        t=D1[i];
        D1[i]=D1[j];
        D1[j]=t;
    }   
}        
for(i=0;i<10;i++)        
{        
printf("%lf\n ",D1[i]);        
}        
    printf("\n");   
    }   

[此贴子已经被作者于2020-5-23 16:07编辑过]

搜索更多相关主题的帖子: i++ for printf 错误 计算 
2020-05-23 15:12
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 
92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000

92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000
 92559631349317831000000000000000000000000000000000000000000000.000000

Press any key to continue
2020-05-23 16:07
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 
  #include<stdio.h>        
    #include<math.h>        
    void main()        
    {        
            int i,j,k;

double a1[3]={1,2,3    },a2[10][3]={{2,3,4},{3,4,5},{4,5,6},{7,8,9},{10,11,12},{13,14,15},{16,17,18},{19,20,21},{22,23,24},{25,26,27}};            

 double D0[10],D1[10],D2[10],D3[10],D4[10],D5[10],D6[10],D7[10],D8=0,D9=0,D10=0,D11=0,D12=0,h,l,t;            
for(i=0;i<10;i++)            
    {        
        D0[i]=fabs(a1[2]-a2[i][2]);  D1[i]=fabs(a1[2]-a2[i][2]);   
    }        
for(i=0;i<10;i++)        
    {   
    D8+=D0[i];   
    }   
for(i=0;i<10;i++)        
{        
printf("%lf\n ",D0[i]);        
}        
    printf("\n");   

for(i=0;i<10-1;i++)        
for(j=i+1;j<10;j++)        
{        
    if(D1[i]>D1[j])   
    {   
        t=D1[i];
        D1[i]=D1[j];
        D1[j]=t;
    }   
}        
for(i=0;i<10;i++)        
{        
printf("%lf\n ",D1[i]);        
}        
    printf("\n");   
    }   
2020-05-23 16:21
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 

找到错误了!


1.000000
 2.000000
 3.000000
 6.000000
 9.000000
 12.000000
 15.000000
 18.000000
 21.000000
 24.000000

1.000000
 2.000000
 3.000000
 6.000000
 9.000000
 12.000000
 15.000000
 18.000000
 21.000000
 24.000000

Press any key to continue
2020-05-23 16:22
快速回复:求教,这个程序为什么计算错误?
数据加载中...
 
   



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

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