?? 例1.cpp
字號(hào):
#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);//逐個(gè)輸入結(jié)構(gòu)體成員
scanf("%f,%f",&b.real,&b.imag);
c=add(a,b);//結(jié)構(gòu)體變量作為函數(shù)參數(shù)和賦值運(yùn)算
output(&a);output(&b);output(&c);//結(jié)構(gòu)體變量的地址作為實(shí)參
}
struct complex add(struct complex x,struct complex y)
{ struct complex z;
z.real=x.real+y.real;//結(jié)構(gòu)體成員進(jìn)行加運(yùn)算和賦值運(yùn)算
z.imag=x.real+y.imag;
return z;//結(jié)構(gòu)體變量作為返回值
}
void output(struct complex*p)//結(jié)構(gòu)體指針作為形參
{ printf("%0.2f+%0.2fi\n",p->real,p->imag);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -