在学习结构体,使用函数调用的过程中遇到一个问题
#include <stdio.h>
struct complex_struct {double x,y;};
void print_complex(struct complex_struct z)
{
if(z.x==0&&z.y==0)
{
printf("0");
}
else if(z.x==0&&z.y!=0)
{
printf("%.1fi",z.y);
}
else if(z.x!=0&&z.y==0)
{
printf("%.1f",z.x);
}
else
{
printf("%.1f+%fi",z.x,z.y);
}
}
main()
{
struct complex_struct {double x,y;};
struct complex_struct z1;
z1.x=3.0;
z1.y=4.0;
print_complex(z1);
}
#include <stdio.h>
struct complex_struct {double x,y;};
void print_complex(struct complex_struct z)
{
if(z.x==0&&z.y==0)
{
printf("0");
}
else if(z.x==0&&z.y!=0)
{
printf("%.1fi",z.y);
}
else if(z.x!=0&&z.y==0)
{
printf("%.1f",z.x);
}
else
{
printf("%.1f+%fi",z.x,z.y);
}
}
main()
{
struct complex_struct z1;
z1.x=3.0;
z1.y=4.0;
print_complex(z1);
}