complex.c

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

C
41
字号
#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 itstruct complex add(struct complex first, struct complex second);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);	ans = add(num1, num2);	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;}struct complex add (struct complex first, struct complex second){	struct complex result;	result.real = first.real + second.real;	result.imag = first.imag + second.imag;	/* Identical result, less typing:		struct complex result = first;		result.real += second.real;		result.imag += second.imag; */	return result;}

⌨️ 快捷键说明

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