复数的四则运算

#include<stdio.h>
#include<stdlib.h>
void add_state(float a, float b, float x, float y)
{
	float m = a + x;
	float n = b + y;
	if (n > 0)
		printf("%f+%fi\n", m, n);
	else
		printf("%f%fi\n", m, n);
}
void sub_state(float a, float b, float x, float y)
{
	float m = a - x;
	float n = b - y;
	if (n > 0)
		printf("%f-%fi\n", m, n);
	else
		printf("%f%fi\n", m, n);
}
void mul_state(float a, float b, float x, float y)
{
	float m = a*x - b*y;
	float n = a*y + b*x;
	if (n > 0)
		printf("%f+%fi\n", m, n);
	else
		printf("%f%fi\n", m, n);

}
void div_state(float a, float b, float x, float y)
{
	float m = (a*x + b*y) / (x*x + y*y);
	float n = (-a*y + b*x) / (x*x + y*y);
	if (n > 0)
		printf("%f+%fi\n", m, n);
	else
		printf("%f%fi\n", m, n);
}
struct  pluar
{
	float real;
	float imag;
	char i;
};

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include"windly.h"
int main()
{
	printf("**************两个复数之间的运算**************\n");
	printf("请按照标准形式 a+bi 输入复数,其中a,b不可缺省\n");
	struct pluar num1 = { 0 };
	struct pluar num2 = { 0 };
	char sym[2];
	scanf("%f%f%s", &num1.real, &num1.imag, &num1.i);
	scanf("%s",sym);
	scanf("%f%f%s", &num2.real, &num2.imag, &num2.i);
	switch (sym[0])
	{
	case '+':
		add_state(num1.real, num1.imag, num2.real, num2.imag);
		break;
	case '-':
		sub_state(num1.real, num1.imag, num2.real, num2.imag);
		break;
	case '*':
		mul_state(num1.real, num1.imag, num2.real, num2.imag);
		break;
	case '/':
		div_state(num1.real, num1.imag, num2.real, num2.imag);
		break;
	default:
		printf("NULL");
		break;
	}
	system("pause");
	return 0;
}

转载于:https://www.cnblogs.com/Sunnylunch/p/5483140.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值