Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
can';t对'进行乘法运算;双倍';数字_C_Double_Multiplication - Fatal编程技术网

can';t对'进行乘法运算;双倍';数字

can';t对'进行乘法运算;双倍';数字,c,double,multiplication,C,Double,Multiplication,我正在尝试为复杂类型的数字编写一些函数,但我无法实现 #include<stdio.h> #include<stdlib.h> #include<math.h> typedef struct{ double a; /* Real*/ double b; /* Imaginary*/ }Complex; Complex Nmbr1,Nmbr2; int main() { Complex NmbrMulti; printf("Type the value of

我正在尝试为复杂类型的数字编写一些函数,但我无法实现

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef struct{
double a; /* Real*/
double b; /* Imaginary*/
}Complex;
Complex Nmbr1,Nmbr2;

int main()
{
Complex NmbrMulti;
printf("Type the value of the real part of the first number\n");
scanf("%d",&Nmbr1.a);
printf("\nType the value of the Imaginary part of the first number\n");
scanf("%d",&Nmbr1.b);
printf("\nType the value of the real part of the second number\n");
scanf("%d",&Nmbr2.a);
printf("\nType the value of the Imaginary part of the second number\n");
scanf("%d",&Nmbr2.b);

   NmbrMulti.a = Nmbr1.a  * Nmbr2.a  - Nmbr1.b * Nmbr2.b ;
   NmbrMulti.b = Nmbr1.a * Nmbr2.b + Nmbr2.a * Nmbr1.b ;

  printf("\nThe Multiplication : %d+i", NmbrMulti.a);
  printf("%d\n", NmbrMulti.b);

return 0;
}
#包括
#包括
#包括
类型定义结构{
双a;/*实*/
双b;/*虚*/
}复杂的;
复合物Nmbr1,Nmbr2;
int main()
{
复杂NmbrMulti;
printf(“键入第一个数字的实部值\n”);
scanf(“%d”和Nmbr1.a);
printf(“\n键入第一个数字的虚部的值\n”);
scanf(“%d”和Nmbr1.b);
printf(“\n键入第二个数字的实部的值\n”);
scanf(“%d”和Nmbr2.a);
printf(“\n键入第二个数字的虚部的值\n”);
scanf(“%d”和Nmbr2.b);
NmbrMulti.a=Nmbr1.a*Nmbr2.a-Nmbr1.b*Nmbr2.b;
NmbrMulti.b=Nmbr1.a*Nmbr2.b+Nmbr2.a*Nmbr1.b;
printf(“\n乘法:%d+i”,NmbrMulti.a);
printf(“%d\n”,NmbrMulti.b);
返回0;
}

但是我得到的结果是,
0+i0
,似乎问题出在运算上,有没有另一种方法可以对我不知道的双数进行乘法

scanf
看到
%d
时,相应的参数必须是指向
int
的指针。如果参数是指向
double
的指针,则代码应为
%lf

参考

C中的
double
格式是
lf
,而不是
d
。后者表示and
int