complex2.c

来自「C源码集」· C语言 代码 · 共 34 行

C
34
字号
#include <stdio.h>	struct complex	{		float real;		float imag;	};// define structure outside main in pre=processor area to make// it global. Otherwise functions will not know about itvoid add(struct complex *first, struct complex *second,			struct complex *ans);int main (){	struct complex num1 = {1.7, 3.4}, num2, ans;	num2.real = 5.1;	num2.imag = 2.3;	// or scanf("%f %f", num2.real, num2.imag);	add(&num1, &num2, &ans);	printf("(%5.2f, %5.2f) + (%5.2f, %5.2f) is (%5.2f, %5.2f)\n",				num1.real, num1.imag, num2.real, num2.imag, ans.real, ans.imag);	return 0;}void add (struct complex *first, struct complex *second,				struct complex *result){	result -> real = first -> real + second -> real;	(*result).imag = (*first).imag + (*second).imag;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?