问题描述
- 关于实参与形参类型不一致问题求解
-
#include<stdio.h> #include<math.h> double e(double *u,double *v) { *u=exp(*u)*cos(*v); *v=exp(*u)*sin(*v); return ; } double ln(double *u,double *v) { *u=ln(sqrt((*u)*(*u)+(*v)*(*v))); *v=atan((*v)/(*u)); return; } double sin(double *u,double *v) { *u=sin(*u)*(exp(*v)+exp(-(*v)))/2; *v=cos(*u)*(exp(*v)-exp(-(*v)))/2; return; } double cos(double *u,double *v) { *u=cos(*u)*(exp(*v)+exp(-(*v)))/2; *v=-sin(*u)*(exp(*v)-exp(-(*v)))/2; return; } main() { double x,y,a,b; double e(double *,double *); double ln(double *,double *); double sin(double *,double *); double cos(double *,double *); printf("请输入复数的实部和虚部x,y:"); scanf("%lf%lf",&x,&y); a=x;b=y; e(&x,&y); printf("exp(%f+%fi)=%f+%fin",a,b,x,y); x=a;y=b; ln(&x,&y); printf("ln(%f+%fi)=%f+%fin",a,b,x,y); x=a;y=b; sin(&x,&y); printf("sin(%f+%fi)=%f+%fin",a,b,x,y); x=a;y=b; cos(&x,&y); printf("cos(%f+%fi)=%f+%fin",a,b,x,y); }
问题如下:
1,错误 16 error C2198: “cos”: 用于调用的参数太少
2,错误 2 error C2440: “函数”: 无法从“double”转换为“double *”
( 21 IntelliSense: "double" 类型的实参与 "double *" 类型的形参不兼容 )
3, 警告 13 warning C4029: 声明的形参表不同于定义4,警告 1 warning C4033: “e”必须返回值
不明白这是为什么,希望高手指点。
解决方案
#include<stdio.h>
#include<math.h>
void e(double *u,double *v)//修改
{
*u=exp(*u)*cos(*v);
*v=exp(*u)*sin(*v);
}
void ln(double *u,double *v)//修改
{
*u=log(sqrt((*u)*(*u)+(*v)*(*v)));//修改
*v=atan((*v)/(*u));
}
void sin(double *u,double *v)//修改
{
*u=sin(*u)*(exp(*v)+exp(-(*v)))/2;
*v=cos(*u)*(exp(*v)-exp(-(*v)))/2;
}
void cos(double *u,double *v)//修改
{
*u=cos(*u)*(exp(*v)+exp(-(*v)))/2;
*v=-sin(*u)*(exp(*v)-exp(-(*v)))/2;
}
void main()
{
double x,y,a,b;
printf("请输入复数的实部和虚部x,y:");
scanf("%lf%lf",&x,&y);
a=x;b=y;
e(&x,&y);
printf("exp(%lf+%lfi)=%lf+%ln",a,b,x,y);//修改
x=a;y=b;
ln(&x,&y);
printf("ln(%lf+%lfi)=%l+%lfin",a,b,x,y);//修改
x=a;y=b;
sin(&x,&y);
printf("sin(%lf+%lfi)=%lf+%lfin",a,b,x,y);//修改
x=a;y=b;
cos(&x,&y);
printf("cos(%lf+%lfi)=%lf+%lfin",a,b,x,y);//修改
}
时间: 2024-10-02 22:46:01