随笔-48  评论-259  文章-1  trackbacks-0

#include<iostream.h>
typedef float * Complex;
Status InitComplex(Complex &C,float r1,float r2){
  C=new float[2];
  if(!C) return OVERFLOW;
  C[0]=r1;C[1]=r2;
  return OK;
}
Status DestoryComplex(Complex &C){
  delete[] C;
  return OK;
}
Status OutPut(Complex C){

  if(C[0]==0&&C[1]==0) cout<<0;
  if(C[0]&&C[1]>0) cout<<C[0]<<'+'<<C[1]<<'i';
  if(C[0]&&C[1]<0) cout<<C[0]<<C[1]<<'i';
  if(C[0]&&C[1]==0) cout<<C[0];
  if(C[0]==0&&C[1]) cout<<C[1]<<'i';

  return OK;
}
Status GetRe(Complex C,float &r1){
  r1=C[0];
  return OK;
}
Status GetIm(Complex C,float &r2){
  r2=C[1];
  return OK;
}
Status AddComplex(Complex C1,Complex C2,Complex &C){
  InitComplex(C,C1[0]+C2[0],C1[1]+C2[1]);
  return OK;
}
Status ReduceComplex(Complex C1,Complex C2,Complex &C){
  InitComplex(C,C1[0]-C2[0],C1[1]-C2[1]);
  return OK;
}
Status ChengfaComplex(Complex C1,Complex C2,Complex &C){
  float r1,r2;
  r1=C1[0]*C2[0]-C1[1]*C2[1];
  r2=C1[0]*C2[1]+C1[1]*C2[0];
  InitComplex(C,r1,r2);
  return OK;
}

posted on 2007-06-06 23:42 星梦情缘 阅读(1530) 评论(3)  编辑 收藏 引用 所属分类: 数据结构的所有实现程序

评论:
# re: C语言版--复数的实现 2007-06-06 23:43 | 星梦情缘
大家假如有希望我把所有的程序都发上来的话,就在这里说下哈  回复  更多评论
  
# re: C语言版--复数的实现 2007-06-09 10:17 | 学习
有!!  回复  更多评论
  
# re: C语言版--复数的实现 2009-01-08 18:43 | 31688378
垃圾代码  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理