作业帮 > 综合 > 作业

C语言 定义一个复数结构,求两个复数的和与积

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/10 15:32:17
C语言 定义一个复数结构,求两个复数的和与积
是要流程图啊!1
C语言 定义一个复数结构,求两个复数的和与积
刚学习也 写的不细致.
忽忽~我错咯~我自己看书,半个月,还没看到那去,肯定写搞笑咯,我表示的只是一个形式,非真正的复数也~算咯,摆那我也不删它咯.

你可以不用函数,自己改了就行.

/**

* Generate the sum and product of two plural numbers.

*/

#include

struct pluralNum {

float x; float y;};

int main(void)

{

struct pluralNum p1,p2;

struct pluralNum getPluralNum(void);

void calSum(struct pluralNum a,struct pluralNum b);

void calProduct(struct pluralNum a,struct pluralNum b);

p1 = getPluralNum();

p2 = getPluralNum();

calSum(p1,p2);

calProduct(p1,p2);

printf("Thank You!\n");

return 0;

}

struct pluralNum getPluralNum(void)

{

struct pluralNum temp;

static int count = 1;

printf("Please specify the plural number.\n");

printf("real number:x = ");

scanf("%f",&temp.x);

printf("imaginary number:y = ");

scanf("%f",&temp.y);

printf("You specified the plural number p%i =:\n",count);

printf("%.2f+%.2fi\n",temp.x,temp.y);

count++;

return (temp);

}

void calSum(struct pluralNum a,struct pluralNum b)

{

printf("The sum of p1 and p2 is:\n");

printf("%.2f+%.2fi\n",a.x + b.x,a.y + b.y);

}

void calProduct(struct pluralNum a,struct pluralNum b)

{

float realNum,imaginaryNum;

realNum = a.x * b.x - a.y * b.y;

imaginaryNum = a.x * b.y + b.x * a.y;

printf("The product of p1 and p2 is:\n");

printf("%.2f+%.2fi\n",realNum,imaginaryNum);

}