复数
来源:互联网 发布:乐视电视怎么样 知乎 编辑:程序博客网 时间:2024/04/28 05:36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Complex
{
public struct Complex
{
public int RealPart;
public int ImaginPart;
public Complex(int RealPart, int ImaginPart)
{
this.RealPart = RealPart;
this.ImaginPart = ImaginPart;
}
public static Complex operator +(Complex a, Complex b)
{
return new Complex(a.RealPart + b.RealPart, a.ImaginPart + b.ImaginPart);
}
public override string ToString()
{
return (String.Format("{0}+{1}i", RealPart, ImaginPart));
}
}
class TestComplex
{
static void Main()
{
Complex num1 = new Complex(1, 2);
Complex num2 = new Complex(3, 4);
Complex complexAdd = num1 + num2;
Console.WriteLine("第一个复数:{0}", num1);
Console.WriteLine("第二个复数:{0}", num2);
Console.WriteLine("两个复数之和:{0}", complexAdd);
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Complex
{
public struct Complex
{
public int RealPart;
public int ImaginPart;
public Complex(int RealPart, int ImaginPart)
{
this.RealPart = RealPart;
this.ImaginPart = ImaginPart;
}
public static Complex operator +(Complex a, Complex b)
{
return new Complex(a.RealPart + b.RealPart, a.ImaginPart + b.ImaginPart);
}
public override string ToString()
{
return (String.Format("{0}+{1}i", RealPart, ImaginPart));
}
}
class TestComplex
{
static void Main()
{
Complex num1 = new Complex(1, 2);
Complex num2 = new Complex(3, 4);
Complex complexAdd = num1 + num2;
Console.WriteLine("第一个复数:{0}", num1);
Console.WriteLine("第二个复数:{0}", num2);
Console.WriteLine("两个复数之和:{0}", complexAdd);
Console.ReadKey();
}
}
}
0 0
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- 复数
- LayoutInflater的inflate函数用法详解
- 织梦文章页/列表页调用评论数、好评、差评的sql语句
- ArrayList和Vector的区别,HashMap和Hashtable的区别以及线程安全的理解
- C++_运算符重载
- android源码编译错误make ***[out/host/linux-x86/obj/EXECUTABL
- 复数
- Android 绘制文本垂直居中
- 关于js的冒泡事件,和一款基于jQuery的联动Select下拉框
- 用实例给新手讲解RSA加密算法
- 配置Android Studio的环境变量
- XML总结
- CSDN高校俱乐部 编程挑战--五子棋
- PL/SQL 数据类型和变量 -- 字符
- DEDEv5.3动态调用顶一下和踩一下的方法