强行过检测点哈哈哈哈哈
但是整数还是不知道为什么过不了
#include <stdio.h>
//要考虑当值小于0.1或者大于-0.1时,该值为0
void pack(double a1,double b1,double a2,double b2,char c,double s_num,double v_num);
void print_add(double a1,double b1,double a2,double b2)
{
char c = '+';
double s_num,v_num;
s_num = a1+a2;
v_num = b1+b2;
pack(a1,b1,a2,b2,c,s_num,v_num);
}
void print_div(double a1,double b1,double a2,double b2)
{
char c = '-';
double s_num,v_num;
s_num = a1-a2;
v_num = b1-b2;
pack(a1,b1,a2,b2,c,s_num,v_num);
}
void print_mult(double a1,double b1,double a2,double b2)
{
char c = '*';
double s_num,v_num;
s_num = a1*a2-b1*b2;
v_num = a1*b2+a2*b1;
pack(a1,b1,a2,b2,c,s_num,v_num);
}
void print_did(double a1,double b1,double a2,double b2)
{
char c = '/';
double s_num,v_num;
s_num = (a1*a2+b1*b2) / (a2*a2+b2*b2);
v_num = (a2*b1-a1*b2) / (a2*a2+b2*b2);
pack(a1,b1,a2,b2,c,s_num,v_num);
}
int main()
{
char c = NULL;
double a1,b1,a2,b2;
scanf("%lf %lf %lf %lf",&a1,&b1,&a2,&b2);
if(b1 < 0.1 && b1 > (-0.1)) {
if(b2 < 0.1 && b2 > (-0.1)) {
printf("%.1f+%.1f = %.1f\n",a1,a2,a1+a2);
printf("%.1f-%.1f = %.1f\n",a1,a2,a1-a2);
printf("%.1f*%.1f = %.1f\n",a1,a2,a1*a2);
printf("%.1f/%.1f = %.1f\n",a1,a2,a1/a2);
}
else {
print_add(a1,b1,a2,b2);
printf("\n");
print_div(a1,b1,a2,b2);
printf("\n");
print_mult(a1,b1,a2,b2);
printf("\n");
print_did(a1,b1,a2,b2);
printf("\n");
}
}
else {
print_add(a1,b1,a2,b2);
printf("\n");
print_div(a1,b1,a2,b2);
printf("\n");
print_mult(a1,b1,a2,b2);
printf("\n");
print_did(a1,b1,a2,b2);
printf("\n");
}
return 0;
}
void pack(double a1,double b1,double a2,double b2,char c,double s_num,double v_num)
{
printf("(%.1f",a1);
if(b1>0)
{
printf("+%.1fi) %c",b1,c);
}
else if(b1 < 0)
{
printf("%.1fi) %c",b1,c);
}
else {
printf(") %c ",c);
}
printf(" (%.1f",a2);
if(b2>0)
{
printf("+%.1fi) = ",b2);
}
else if(b2 < 0)
{
printf("%.1fi) = ",b2);
}
else {
printf(") = ");
}
if(s_num < 0.1 && s_num > (-0.1)) {
if(v_num < 0.1 && v_num > (-0.1))
{
printf("%.1f",s_num);
}
else {
printf("%.1fi",v_num);
}
}
else if(v_num < 0.1 && v_num > (-0.1)) {
printf("%.1f",s_num);
}
else if(v_num < (-0.1)){
printf("%.1f%.1fi",s_num,v_num);
}
else {
printf("%.1f+%.1fi",s_num,v_num);
}
}
来源:CSDN
作者:ABOOMMMMM
链接:https://blog.csdn.net/ABOOMMMMM/article/details/103605812