刚学编程,想写个能运算四则运算的程序,为啥提示我出现严重错误啊
#include<stdio.h>
int main() {
double a, b, c, d,x,y,t;
char op,tmp;
printf("\n请输入第一个复数的实部和虚部:");
scanf_s("%lf %lf", &a, &b);
printf("\n请输入运算符:");
scanf_s("%c %c",&tmp,&op );
printf("\n请输入第二个复数的实部和虚部:");
scanf_s("%lf %lf", &c, &d);
switch (op) {
case'+':
x = a + b;
y = c + d;
break;
case'-':
x = a - b;
y = c - d;
break;
case'*':
x = a * c - b * d;
y = b * c + a * d;
break;
case'/':
t = c * c - d * d;
if (t==0) {
printf("分母不为零");
return 0;
}
else
x = (a * c + b * d) / (c * c - d * d);
y = (b * c - a * d) / (c * c - d * d);
break;
default:
printf("invalidation operator\n");
return 0;
}
printf("复数的运算的结果为:%lf+%lfi",x,y);
return 0;
}
编程出现问题,如何解决?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注 本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用亖夕 2022-09-04 02:22#include<stdio.h> int main() { double a, b, c, d,x,y,t; char op,tmp; printf("\n请输入第一个复数的实部和虚部:"); scanf_s("%lf %lf", &a, &b); printf("\n请输入运算符:"); fflush(stdin); scanf_s("%c",&op ); printf("\n请输入第二个复数的实部和虚部:"); fflush(stdin); scanf_s("%lf %lf", &c, &d); switch (op) { case'+': x = a + b; y = c + d; break; case'-': x = a - b; y = c - d; break; case'*': x = a * c - b * d; y = b * c + a * d; break; case'/': t = c * c - d * d; if (t==0) { printf("分母不为零"); return 0; } else x = (a * c + b * d) / (c * c - d * d); y = (b * c - a * d) / (c * c - d * d); break; default: printf("invalidation operator\n"); return 0; } printf("复数的运算的结果为:%lf+%lfi",x,y); return 0; }
赞回复