📄 例1.cpp
字号:
#include<stdio.h>
struct complex
{ float real,imag;
};
void main()
{ struct complex add(struct complex,struct complex);
void output(struct complex*);
struct complex a,b,c;
scanf("%f,%f",&a.real,&a.imag);//逐个输入结构体成员
scanf("%f,%f",&b.real,&b.imag);
c=add(a,b);//结构体变量作为函数参数和赋值运算
output(&a);output(&b);output(&c);//结构体变量的地址作为实参
}
struct complex add(struct complex x,struct complex y)
{ struct complex z;
z.real=x.real+y.real;//结构体成员进行加运算和赋值运算
z.imag=x.real+y.imag;
return z;//结构体变量作为返回值
}
void output(struct complex*p)//结构体指针作为形参
{ printf("%0.2f+%0.2fi\n",p->real,p->imag);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -