| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2421 人关注过本帖
标题:[分享]me复数c的程序
只看楼主 加入收藏
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
 问题点数:0 回复次数:15 
[分享]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
谁与争疯
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:海南省
等 级:版主
威 望:191
帖 子:15071
专家分:17513
注 册:2007-4-22
收藏
得分:0 
你也会发程序?
copy来的!

论坛是我家灌水靠大家
2007-06-14 23:28
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
谁与争疯
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:海南省
等 级:版主
威 望:191
帖 子:15071
专家分:17513
注 册:2007-4-22
收藏
得分:0 
这程序,是干什么用的?

论坛是我家灌水靠大家
2007-06-14 23:32
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 

复数的四则运算


中環nite 燈光閃閃...
2007-06-14 23:35
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 

nice work, you could gradaute from C language class now.

But before you advance to C++ or more advanced programming fileds, you may want to answer the following C syntax problems.

What a, b, c, and d are in the following.


int *(*a())[10];

int *(*b[5])();

int (*c[5])();

int (*d(int))[2];

[此贴子已经被作者于2007-6-15 3:07:38编辑过]


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-06-15 02:59
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 

中環nite 燈光閃閃...
2007-06-15 12:30
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
Did you figure it out or not? I only see two tear-dropping faces above.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-06-15 16:26
viky
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1752
专家分:0
注 册:2007-5-31
收藏
得分:0 
汗啊!为什么祢要装英文系统呢?装双系统不好吗?
双系统比较快!

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



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

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