C语言 定义一个复数结构,求两个复数的和与积是要流程图啊!1
C语言 定义一个复数结构,求两个复数的和与积
是要流程图啊!1
刚学习也 写的不细致.
忽忽~我错咯~我自己看书,半个月,还没看到那去,肯定写搞笑咯,我表示的只是一个形式,非真正的复数也~算咯,摆那我也不删它咯.
你可以不用函数,自己改了就行.
/**
* 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);
}