复数输出

这是课堂练习

#include<stdio.h>

#include "df.h"//文件命名为英文,不是汉字,不带符号

typedef struct   

{

    float  x;

    float  y;

}complex;

Status initcomplex (complex &z,float r,float i)

{

    z.x=r;

    z.y=i;

 return OK;

}

Status getreal(complex z,float &r)//main中z已经定义

{

    r=z.x;

 return OK;//return 0或1没有关系,此时r值不需要传回,是引用!

}

int main()

{

    complex z;

    float r;

    initcomplex (z,2.0,3.0);

    getreal(z,r);

    printf("%.1lf\n",r);

    return 0;

}

另一个代码

 

#include<stdio.h>

#include "df.h"



typedef struct  

{

    float  x;

    float  y;

} complex;

float rr;

Status initcomplex (complex &z,float r,float i)

{

    z.x=r;

    z.y=i;

	return OK;

}

Status getreal(complex &z)

{

    rr=z.x;

	return OK;

}

Status getimag(complex &z)

int main()

{

    complex z;

	float a,b,r;

	float t1=0,t2=0;

    while(scanf("%lf%lf",&a,&b)!=EOF)

	{

		init(&z,a,b);

		getreal(z,&r);

		t1+=r;

		

	}

}


 


 

 

你可能感兴趣的:(输出)