ho14_1.c

来自「Software Development in C: A Practical A」· C语言 代码 · 共 47 行

C
47
字号
#include <stdio.h>

struct complex_number
{
	double i,j;
};


int main()
{
	struct complex_number aComplexNumber;
	struct complex_number anotherComplexNumber;
	struct complex_number result;

	printf("\nPlease enter a complex number. Type the\n");
	printf("imaginary part of the number, then press Enter.");
	printf("\nNext, type the real part of the ");
	printf("number.\n");
	printf("Imaginary part: ");
	scanf("%lf",&aComplexNumber.i);
	printf("Real part: ");
	scanf("%lf",&aComplexNumber.j);

	printf("\nPlease enter another complex number. \n");
	printf("Imaginary part: ");
	scanf("%lf",&anotherComplexNumber.i);
	printf("Real part: ");
	scanf("%lf",&anotherComplexNumber.j);

	result.i = aComplexNumber.i + anotherComplexNumber.i;
	result.j = aComplexNumber.j + anotherComplexNumber.j;

	printf("\n");
	printf("  (%lfi + %lfj)\n",
		   aComplexNumber.i,
		   aComplexNumber.j);
	printf("+ (%lfi + %lfj)\n",
		   anotherComplexNumber.i,
		   anotherComplexNumber.j);
	printf("--------------------------\n");
	printf("  (%lfi + %lfj)\n",
		   result.i,
		   result.j);
	printf("\n");

	return (0);
}

⌨️ 快捷键说明

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