c语言:输入俩个复数的实部与虚部,计算俩个复数之积,求解为何错了?声明怎么声明? 10
#include<stdio.h>floatresult_real,result_imag;intmain(void){floatimag1,imag2,real1,re...
#include<stdio.h>
float result_real,result_imag;
int main(void)
{
float imag1,imag2,real1,real2;
printf("enter 1st complex number(real and imaginary):");
scanf("%f%f",&real1,&imag1);
printf("enter 2nd complex number(real and imaginary):");
scanf("%f%f",&real2,&imag2);
printf("product of complex is %f+%fi\n",result_real,result_imag);
return 0;
}
void complex_prod(float x1,y1,x2,y2);
{
float result_real,result_imag;
result_real=x1*x2-y1*y2);
result_imag=x1*y2+x2*y1;
return result_real,result_imag;
} 展开
float result_real,result_imag;
int main(void)
{
float imag1,imag2,real1,real2;
printf("enter 1st complex number(real and imaginary):");
scanf("%f%f",&real1,&imag1);
printf("enter 2nd complex number(real and imaginary):");
scanf("%f%f",&real2,&imag2);
printf("product of complex is %f+%fi\n",result_real,result_imag);
return 0;
}
void complex_prod(float x1,y1,x2,y2);
{
float result_real,result_imag;
result_real=x1*x2-y1*y2);
result_imag=x1*y2+x2*y1;
return result_real,result_imag;
} 展开
展开全部
#include<stdio.h>
float result_real,result_imag;
void complex_prod(float x1, float y1,float x2,float y2) ; //声明函数
int main(void)
{
float imag1,imag2,real1,real2;
printf("enter 1st complex number(real and imaginary):");
scanf("%f%f",&real1,&imag1);
printf("enter 2nd complex number(real and imaginary):");
scanf("%f%f",&real2,&imag2);
complex_prod(real1,imag1,real2,imag2); //调用函数
printf("product of complex is %f+%fi\n",result_real,result_imag);
return 0;
}
void complex_prod(float x1, float y1,float x2,float y2)//这里多了分号,参数定义错
{
//float result_real,result_imag; 不要了,用全局变量
result_real=x1*x2-y1*y2; //
result_imag=x1*y2+x2*y1;
//return result_real,result_imag; 用不到
}
展开全部
#include <stdio.h>
float result_real,result_imag;
void complex_prod(float x1,float y1,float x2,float y2) {
// float result_real,result_imag;
result_real = x1*x2 - y1*y2;
result_imag = x1*y2 + x2*y1;
// return result_real,result_imag;
}
int main(void) {
float imag1,imag2,real1,real2;
printf("enter 1st complex number(real and imaginary):");
scanf("%f%f",&real1,&imag1);
printf("enter 2nd complex number(real and imaginary):");
scanf("%f%f",&real2,&imag2);
complex_prod(real1,imag1,real2,imag2); // 调用函数后,才能使全局变量得到计算结果
printf("product of complex is %f+%fi\n",result_real,result_imag);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
float result_real,result_imag;
int main(void)
{
float imag1,imag2,real1,real2;
printf("enter 1st complex number(real and imaginary):");
scanf("%f%f",&real1,&imag1);
printf("enter 2nd complex number(real and imaginary):");
scanf("%f%f",&real2,&imag2);
printf("product of complex is %f+%fi\n",result_real,result_imag);/*complex_prod函数没有调用result_real,result_imag还没有值 而且还要在调用前声明一下*/
return 0;
}
void complex_prod(float x1,y1,x2,y2);/*函数参数不能这样定义*/
{
float result_real,result_imag;
result_real=x1*x2-y1*y2);
result_imag=x1*y2+x2*y1;
return result_real,result_imag;/*定义的函数返回值为空 这里就不能加返回值*/
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询