Click here to Skip to main content
15,896,435 members
Articles / Programming Languages / C++

A class for operations with Large Integer Numbers

Rate me:
Please Sign up or sign in to vote.
4.91/5 (14 votes)
26 May 2003Ms-PL 126.9K   2.4K   41  
Presenting some algorithms for operations with large integer numbers in a C++ class using the STL vector container
// Test.cpp : Defines the entry point for the console application.
//

#include "LargeNumber.h"
#include <iostream>

using namespace std;

//Factorial calculation
CLargeNumber Factorial(int iNumber)
{
	CLargeNumber oLN("1");
	if(iNumber > 1)
	{
		for(int i=2; i<=iNumber; i++)
			oLN *= i;
	}
	return oLN;
}

void main()
{

	CLargeNumber oLN1 = CLargeNumber(1000000);
	oLN1 -= CLargeNumber(2000000);
	cout << oLN1.ToString() << endl;
  
	//Testing the LargeNumber class
/*
	CLargeNumber oLN1("1111111434311111");
	CLargeNumber oLN2("2222222233422222");
	cout << (oLN1+oLN2).ToString() << endl;
*/

/*
	CLargeNumber oLN1("12323523664");
	CLargeNumber oLN2("325454361234");
	cout << (oLN1-oLN2).ToString() << endl;
*/

/*
	CLargeNumber oLN1("123456834333466");
	CLargeNumber oLN2(1000);
	cout << (oLN1*oLN2).ToString() << endl;
*/

/*
	try
	{
		CLargeNumber oLN1("1234655123667");
		CLargeNumber oLN2(500);
		cout << (oLN1/oLN2).ToString() << endl;
		cout << (oLN1%oLN2).ToString() << endl;
	}
	catch(exception& roEx)
	{
		cout << roEx.what() << endl;
	}
*/

/*
	try
	{
		CLargeNumber oLN1("1000000000000000000");
		cout << oLN1.SquareRoot().ToString() << endl;
	}
	catch(exception& roEx)
	{
		cout << roEx.what() << endl;
	}
*/

/*
	//Testing the Factorial Function
	//The 158 digits of 100!
	//9332621544394415268169923885626670049071596826438162146859296389521759999322991
	//5608941463976156518286253697920827223758251185210916864000000000000000000000000
	cout << Factorial(100).ToString() << endl;
*/
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions