| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1079 人关注过本帖
标题:求大神帮我看看哪里出错了 谢谢
只看楼主 加入收藏
zl3119525859
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2015-2-24
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:4 
求大神帮我看看哪里出错了 谢谢

我这是根据书上的题目做的  看了书上的标准答案  但是不知道哪里有错了  编译器不能编译   请帮我检查下哪里错了  

可以的话  请指出那部分有问题  哪里不好    谢谢  

#include <stdio.h>
double source[5]={1.1,2.2,3.3,4.4,5.5};
double target1 [5];
double target2 [5];
void copy_arr(double a1[],double a2[],int n);
void copy_ptr(double *p1,double *p2,int n);
int main()
{
    double source[5]={1.1,2.2,3.3,4.4,5.5};
    double target1 [5]={0};
    double target2 [5]={0};
    void copy_arr(source,target1,5);
    void copy_ptr(source,target2,5);
    printf("原数组 输出结果为\t%g  t%g  t%g  t%g  t%g\n",source{0},source{1},source{2},source{3},source{4});
    printf("使用数组符号的形式 输出结果为\t%g  t%g  t%g  t%g  t%g\n",target1[0],target1[1],target1[2],target1[3],target1[4]);
    printf("使用指针的形式 输出结果为\t%g  t%g  t%g  t%g  t%g\n",target2[0],target2[1],target2[2],target2[3],target2[4]);
    return 0;
}
void copy_arr(double a1[],double a2[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        a1[i]=a2[i];
    }
}
void copy_ptr(double *p1,double *p2,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        p1[i]=p2[i];
    }
}
搜索更多相关主题的帖子: include double source 编译器 
2017-01-26 08:49
renkejun1942
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:不是这样
等 级:贵宾
威 望:33
帖 子:1645
专家分:5297
注 册:2016-12-1
收藏
得分:20 
#include <stdio.h>
double source[5]={1.1,2.2,3.3,4.4,5.5};
double target1 [5];
double target2 [5];
void copy_arr(double a1[],double a2[],int n);
void copy_ptr(double *p1,double *p2,int n);
int main()
{
    double source[5]={1.1,2.2,3.3,4.4,5.5};
    double target1 [5]={0};
    double target2 [5]={0};
    copy_arr(source,target1,5);//去掉void
    copy_ptr(source,target2,5);//去掉void
    printf("原数组 输出结果为\t%g  t%g  t%g  t%g  t%g\n",source[0],source[1],source[2],source[3],source[4]);//偏移量[],你写成了{}
    printf("使用数组符号的形式 输出结果为\t%g  t%g  t%g  t%g  t%g\n",target1[0],target1[1],target1[2],target1[3],target1[4]);
    printf("使用指针的形式 输出结果为\t%g  t%g  t%g  t%g  t%g\n",target2[0],target2[1],target2[2],target2[3],target2[4]);
    return 0;
}
void copy_arr(double a1[],double a2[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        a1[i]=a2[i];
    }
}
void copy_ptr(double *p1,double *p2,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        p1[i]=p2[i];
    }
}

09:30 05/21 种下琵琶种子,能种活么?等待中……
21:50 05/27 没有发芽。
20:51 05/28 没有发芽。
23:03 05/29 没有发芽。
23:30 06/09 我有预感,要发芽了。
2017-01-26 08:59
renkejun1942
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:不是这样
等 级:贵宾
威 望:33
帖 子:1645
专家分:5297
注 册:2016-12-1
收藏
得分:0 
    copy_arr(source,target1,5);
    copy_ptr(source,target2,5);

你这两个调用写错了吧?根据你的两个函数来看,是将a2数组复制给a1数组,但是你的targer1的值全部是0,所以是不是写反了,应该是 copy_arr(target1,source,5)

09:30 05/21 种下琵琶种子,能种活么?等待中……
21:50 05/27 没有发芽。
20:51 05/28 没有发芽。
23:03 05/29 没有发芽。
23:30 06/09 我有预感,要发芽了。
2017-01-26 09:05
zl3119525859
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2015-2-24
收藏
得分:0 
回复 3楼 renkejun1942
还真是的   谢谢啊  找到原因了 编译之后  结果是对的  谢谢哈
2017-01-26 09:34
zl3119525859
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2015-2-24
收藏
得分:0 
回复 2楼 renkejun1942
帮了忙   谢谢哈
2017-01-26 09:34
快速回复:求大神帮我看看哪里出错了 谢谢
数据加载中...
 
   



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

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