复数的四则运算

作者在 2009-01-02 12:37:49 发布以下内容
#include<stdio.h>
#include<malloc.h>
typedef struct fsh
{ float x; 
  float y; 
}fshx,*fshsh;
void createfsh(fshsh *f)
{  *f=(fshsh)malloc(sizeof(fshx));
   printf("Enter shibu&xubu\n");
   scanf("%f%f",&(*f)->x,&(*f)->y);
}
void fshadd(fshsh *f1,fshx f2,fshsh *f3)
{  *f3=(fshsh)malloc(sizeof(fshx));
   (*f3)->x=(*f1)->x+f2.x;
   (*f3)->y=(*f1)->y+f2.y;
}

void fshjf(fshsh *f1,fshx f2,fshsh *f3)
{  *f3=(fshsh)malloc(sizeof(fshx));
   (*f3)->x=(*f1)->x-f2.x;
   (*f3)->y=(*f1)->y-f2.y;
}
 void fshchef(fshsh *f1,fshx f2,fshsh *f3)
{  *f3=(fshsh)malloc(sizeof(fshx));
   (*f3)->x=(*f1)->y*(-f2.y)+(*f1)->x*f2.x; 
   (*f3)->y=(*f1)->y*f2.x+(*f1)->x*f2.y;
}
void fshchf(fshsh *f1,fshx f2,fshsh *f3)
{  *f3=(fshsh)malloc(sizeof(fshx));
   if((f2.y*(f2.y)+f2.x*f2.x)!=0)
   {  (*f3)->x=((*f1)->y*f2.y+(*f1)->x*f2.x)/(f2.y*(f2.y)+f2.x*f2.x);
      (*f3)->y=((*f1)->y*f2.x+(*f1)->x*(-f2.y))/(f2.y*(f2.y)+f2.x*f2.x);}
   else
   printf("There is an error");
}
void main()
{  fshsh f1,f2,f3;
   createfsh(&f1);
   createfsh(&f2);
   fshadd(&f1,*f2,&f3);
   printf("%f,%f\n",(*f3).x,(*f3).y);
   fshjf(&f1,*f2,&f3);
   printf("%f,%f\n",(*f3).x,(*f3).y);
   fshchef(&f1,*f2,&f3);
   printf("%f,%f\n",(*f3).x,(*f3).y);
   fshchf(&f1,*f2,&f3);
   printf("%f,%f\n",(*f3).x,(*f3).y);
}
C语言 | 阅读 4765 次
文章评论,共0条
游客请输入验证码
最新评论