| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2421 人关注过本帖
标题:[分享]me复数c的程序
取消只看楼主 加入收藏
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
 问题点数:0 回复次数:7 
[分享]me复数c的程序

#include<stdio.h>
#include<stdlib.h>
typedef struct Complex
{
float real;
float image;
}Complex;

Complex CreatComplex(float a,float b);
Complex AddComplex(Complex c1,Complex c2);
Complex Subtract_C(Complex c1,Complex c2);
Complex Multiple_C(Complex c1,Complex c2);
Complex Divide_C(Complex c1,Complex c2);
void Print_C(Complex c);

Complex CreatComplex(float a,float b)
{
Complex c;
c.real=a;
c.image=b;
return c;
}

Complex AddComplex(Complex c1,Complex c2)
{
Complex sum;
sum.real=c1.real+c2.real ;
sum.image=c1.image+c2.image ;
return sum;
}


Complex Subtract_C(Complex c1,Complex c2)
{
Complex Sub;
Sub.real=c1.real-c2.real ;
Sub.image=c1.image-c2.image ;
return Sub;
}

Complex Multiple_C(Complex c1,Complex c2)
{
Complex product;
product.real=c1.real*c2.real-c1.image*c2.image;
product.image=c1.real*c2.image+c1.image*c2.real;
return product;
}


Complex Divide_C(Complex c1,Complex c2)
{
Complex quotient;
quotient.real=(c1.real*c2.real+c1.image*c2.image)/(c2.real*c2.real+c2.image*c2.image);
quotient.image=(c1.image*c2.real-c1.real*c2.image)/(c2.real*c2.real+c2.image*c2.image);
return quotient;
}

void Print_C(Complex c)
{
if(c.image==0.0)
printf("%5.2f\n",c.real);
else
if(c.real==0.0)
printf("%5.2fi\n",c.image);
else
printf("%5.2f+%5.2fi\n",c.real,c.image);
}
real_C(Complex c)
{ printf("%5.2f\n",c.real);
return c.real;}
image_C(Complex c)
{printf("%5.2fi\n",c.image);return c.image;}
void Open()
{
printf("*****************************\n");
printf(" complex \n");
printf(" my name:viky\n");
printf("*****************************\n");
printf("make a choce,add or mul\n");
printf("0.exit\n");
printf("1.stand for input+\n");
printf("2.stand for input-\n");
printf("3.stand for input*\n");
printf("4.stand for input/\n");
printf("5.get real part\n");
printf("6.get image part\n");
}
void main()
{Complex z1,z2,sum,Sub,product,quotient;
float e1,e2;
char sym;
int f=-1;
Open();
while(f!=0)
{
scanf("%d",&f);
getchar();
switch(f)
{ case 0:
return;
case 1:
printf("Input z1 like: 3.0+2.1i or -3.0+-2.1i\nz1=");
scanf("%f+%fi",&e1,&e2);
z1=CreatComplex(e1,e2);
printf("Input z2 like: 3.0+2.1i or -3.0+-2.1i\nIf you want to let z1 divide z2, don't input z2=0.0+0.0i!\nz2=");
scanf("%f+%fi",&e1,&e2);
z2=CreatComplex(e1,e2); sum=AddComplex(z1,z2);Print_C(sum);f=-1;Open();break;
case 2:
printf("Input z1 like: 3.0+2.1i or -3.0+-2.1i\nz1=");
scanf("%f+%fi",&e1,&e2);
z1=CreatComplex(e1,e2);
printf("Input z2 like: 3.0+2.1i or -3.0+-2.1i\nIf you want to let z1 divide z2, don't input z2=0.0+0.0i!\nz2=");
scanf("%f+%fi",&e1,&e2);
z2=CreatComplex(e1,e2); Sub=Subtract_C(z1,z2);Print_C(Sub);f=-1;Open();break;
case 3:
printf("Input z1 like: 3.0+2.1i or -3.0+-2.1i\nz1=");
scanf("%f+%fi",&e1,&e2);
z1=CreatComplex(e1,e2);
printf("Input z2 like: 3.0+2.1i or -3.0+-2.1i\nIf you want to let z1 divide z2, don't input z2=0.0+0.0i!\nz2=");
scanf("%f+%fi",&e1,&e2);
z2=CreatComplex(e1,e2);product=Multiple_C(z1,z2);Print_C(product);f=-1;Open();break;
case 4:
printf("Input z1 like: 3.0+2.1i or -3.0+-2.1i\nz1=");
scanf("%f+%fi",&e1,&e2);
z1=CreatComplex(e1,e2);
printf("Input z2 like: 3.0+2.1i or -3.0+-2.1i\nIf you want to let z1 divide z2, don't input z2=0.0+0.0i!\nz2=");
scanf("%f+%fi",&e1,&e2);
z2=CreatComplex(e1,e2);quotient=Divide_C(z1,z2);Print_C(quotient);f=-1;Open();break;
case 5:printf("Input z1 like: 3.0+2.1i or -3.0+-2.1i\nz1=");
scanf("%f+%fi",&e1,&e2);
z1=CreatComplex(e1,e2);
z1.real=real_C(z1);f=-1;Open();break;
case 6:printf("Input z1 like: 3.0+2.1i or -3.0+-2.1i\nz1=");
scanf("%f+%fi",&e1,&e2);
z1=CreatComplex(e1,e2);
z1.image=image_C(z1);f=-1;Open();break;
default: printf("error symbol!!");f=-1;Open();
}

}
}

搜索更多相关主题的帖子: Complex float 复数 include 
2007-06-14 23:27
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 
那是我写的

中環nite 燈光閃閃...
2007-06-14 23:29
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 
本来想在网上找,可是都运行不了,结果呢,自己动手!!!!!!!!!!!!

中環nite 燈光閃閃...
2007-06-14 23:30
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 

复数的四则运算


中環nite 燈光閃閃...
2007-06-14 23:35
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 

中環nite 燈光閃閃...
2007-06-15 12:30
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 
汗啊!为什么祢要装英文系统呢?装双系统不好吗?
双系统比较快!

中環nite 燈光閃閃...
2007-06-15 16:58
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 

中環nite 燈光閃閃...
2007-06-16 23:16
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 
你有现成的?早说嘛,早说我就不用那么辛苦啦!

中環nite 燈光閃閃...
2007-06-17 11:57
快速回复:[分享]me复数c的程序
数据加载中...
 
   



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

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