| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 814 人关注过本帖
标题:结构体作为形参的简单程序,关于复数的计算,函数哪里有问题?
只看楼主 加入收藏
大学新生007
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-3-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
结构体作为形参的简单程序,关于复数的计算,函数哪里有问题?
#include<stdio.h>
struct mycomplex
{
    double real;
    double image;
};
struct mycomplex input(void)
struct mycomplex add(struct mycomplex c1,struct mycomplex c2)
struct mycomplex mul(struct mycomplex c1,struct mycomplex c2)
void output(struct mycomplex c1)
int main(void)
{
 struct mycomplex a,b,c,d;
 a=input();
 b=input();
 c=add(a,b);
 d=mul(a,b);
 output(c);
 output(d);
 return 0;
}
struct mycomplex input(void)
{
  struct mycomplex c1;
    scanf("%lf",&c1.real);
    scanf("%lf",&c1.image);
    return c1;
}
struct mycomplex add(struct mycomplex c1,struct mycomplex c2)
{
    mycomplex c;
    c.real=c1.real+c2.real;
        c.image=c1.image+c2.image;
        return c;
}
struct mycomplex mul(struct mycomplex c1,struct mycomplex c2)
{
    mycomplex d;
    d.real=(c1.real*b.real)+(c2.image*a.image);
    d.image=(c1.real*b.image)+(c2.image*b.real);
    return d;
}
void output(struct mycomplex c1)
{
    printf("%lf+%lf*i",c1.real,c1.image);
}
搜索更多相关主题的帖子: include double return 结构体 
2017-03-22 15:41
yanzy
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:104
专家分:372
注 册:2017-2-7
收藏
得分:20 
程序代码:
#include<stdio.h>
struct mycomplex
{
    double real;
    double image;
};
struct mycomplex input(void);//加上;
struct mycomplex add(struct mycomplex c1, struct mycomplex c2);//加上;
struct mycomplex mul(struct mycomplex c1, struct mycomplex c2);//加上;
void output(struct mycomplex c1);//加上;
    int main(void)
{
    struct mycomplex a, b, c, d;
    a = input();
    b = input();
    c = add(a, b);
    d = mul(a, b);
    output(c);
    output(d);
    return 0;
}
struct mycomplex input(void)
{
    struct mycomplex c1;
    scanf("%lf", &c1.real);
    scanf("%lf", &c1.image);
    return c1;
}
struct mycomplex add(struct mycomplex c1, struct mycomplex c2)
{
    struct mycomplex c; // struct
    c.real = c1.real + c2.real;
    c.image = c1.image + c2.image;
    return c;
}
struct mycomplex mul(struct mycomplex c1, struct mycomplex c2)
{
    struct mycomplex d;// struct
    struct mycomplex a = c1, b = c2;  //加上这行
    d.real = (c1.real*b.real) + (c2.image*a.image);
    d.image = (c1.real*b.image) + (c2.image*b.real);
    return d;
}
void output(struct mycomplex c1)
{
    printf("%lf+%lf*i", c1.real, c1.image);
}


写错的应该这么多,至于算法对不对没仔细看
2017-03-22 15:51
快速回复:结构体作为形参的简单程序,关于复数的计算,函数哪里有问题?
数据加载中...
 
   



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

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