C#实现大数字的运算
1、添加引用:System.Numerics.dll
2、添加命名空间:using System.Numerics;
3、实例:
3.1判断一个数字是不是质数
static void Main(string[] args)
{
Console.WriteLine("请输入一个很大的数字:");
string bigNumber = Console.ReadLine();
BigInteger bigInteger = BigInteger.Parse(bigNumber);
bool isNumber=false;
for (BigInteger i = ; i < BigInteger.Pow(bigInteger, );i++ )
{
if (bigInteger % i == )
{
isNumber = true;
break;
}
}
if (isNumber)
{
Console.WriteLine("不是质数");
}
else
{
Console.WriteLine("是质数");
}
Console.ReadLine();
}
3.2实现两个大数的加减乘除
static void Main(string[] args)
{
Console.Write("请输入第一个大数字:");
string bigNum1 = Console.ReadLine();
BigInteger bigInt1 = BigInteger.Parse(bigNum1); Console.Write("请输入第二个大数字:");
string bigNum2 = Console.ReadLine();
BigInteger bigInt2 = BigInteger.Parse(bigNum2);
Console.Write(Environment.NewLine); BigInteger addNum = bigInt1 + bigInt2;
BigInteger subNum = bigInt1 - bigInt2;
BigInteger purNum = bigInt1 * bigInt2;
BigInteger divNum = bigInt1 / bigInt2; Console.WriteLine("两大数相加结果为:{0}",addNum);
Console.WriteLine("两大数相减结果为:{0}",subNum);
Console.WriteLine("两大数相乘结果为:{0}",purNum);
Console.WriteLine("两大数相除结果为:{0}",divNum); Console.ReadLine();
}

4、这里我没有去深入如何实现大数字的运算,猜测可以用字符数组来完成 参考文章:http://www.codeproject.com/Articles/60108/BigInteger-Library
C#实现大数字的运算的更多相关文章
- 初识Java(Java数字处理类-大数字运算)
一.大数字运算 在 Java 中提供了大数字的操作类,即 java.math.BigInteger 类与 java.math.BigDecimal 类.这两个类用于高精度计算,体重 BigInteg ...
- java学习第13天( java获取当前时间,有关大数据的运算及精确数字运算,Date类)
一 java获取当前时间 学习一个函数,得到当前时间的准确值 System.currectTimeMillis(). 可以得到以毫秒为单位的当前时间.它主要用于计算程序运行时间,long start= ...
- 大数字运算, BigInteger
package com.ykmimi.test1; import java.math.BigInteger; /** * 大数字运算 * @author ukyor * */ public class ...
- 大数字运算——2、BigDecimal
package com.wh.BigInteger; import java.math.BigDecimal; import java.util.Arrays; /** * @author 王恒 * ...
- 学习Java的第十七天——大数字运算
学习内容:大数字运算 代码实现: package 数字处理类; import java.math.BigInteger; public class BigIntegerDemo { public st ...
- Java BigDecimal大数字操作
在java中提供了大数字的操作类,即java.math.BinInteger类和java.math.BigDecimal类.这两个类用于高精度计算,其中BigInteger类是针对大整数的处理类,而B ...
- POJ2389: 大数字乘法算法
2014-12-26 大数字乘法算法一般是采用模拟"小学生乘法演算过程”方法. 主要算法思想: 1. 乘数a第i)位与乘数b第j)位数字相乘,并将该乘积结果放到乘积结果数组product的第 ...
- [SOJ]寻找第k大数字(numberk)
Description 经过长时间的筹备工作,在Jourk,Ronny,Plipala,阿长,阿沈等人的努力下,DM实验室建立起自己的系列网站,其中包括三个大板块:DMOJ首页.DMOJ论坛.DMOJ ...
- TypeScript中处理大数字(会丢失后面部分数字)
为啥要弄这玩意? 最近做数值游戏,需要用到很大的数字,在前端大数字会自动变成e的科学计数法. 有啥问题? 问题: 1. 在传递给服务端时,服务端因为不能处理大数字(怎么就处理不了?!),就想要我传字符 ...
随机推荐
- Java垃圾收集器之--Garbage-First Collector
简介 Garbage-First(G1)垃圾收集器全面支持JDK7 Upate 4及后续版本.G1收集器是一个服务器形式(server-style)的垃圾收集器,主要用于内存大.多处理器的 ...
- 【Flex教程】#009 As/typeof /instanceof /is的作用
“as” :主要用它做类型转化 假设有一个类叫做Class1,我们声明了一个它的对象 c1,如果想要将它转换成Class2类型,只要这样写: Class2(c1); AS3 中的操作符: as 实现就 ...
- Class attributes
In order to print Card objects in a way that people can easily read, we need a mapping from the inte ...
- socket学习笔记——select函数的使用(windows)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <winsock2.h ...
- javascript各种兼容性问题,不断更新
ie6-ie8 不支持textContent支持innerTextchrome 支持textContent innerTextfireFox 仅支持textContent不支持innerTe ...
- App交互demo
Android <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ...
- struts2项目需要加入的jar包
asm-3.3.jarasm-commons-3.3.jarasm-tree-3.3.jarcommons-fileupload-1.2.2.jarcommons-io-2.0.1.jarcommon ...
- jquery的add()方法扩大选择返回
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- swat主流域文件(file.cio)参数详解——引自http://blog.sciencenet.cn/blog-922140-710636.html
% file.clo,即主流域文件用于文件管理,包括与模型选项.气候输入.数据库和输出控制相关的信息. Master Watershed File: file.cio Project Descript ...
- Linux系统在嵌入式硬件上的移植
========================= 基本常识 ========================= 一. Linux系统的基本构成: 1. loader 2. ...