Large number factorial (100!)

Source: Internet
Author: User

#include < "stdafx.h"
IntMain){

Constint MAX =10000;
int carry_ =0;Carry
int temp =1;Product
int Num[max] = {0};The number of saved
int num_n =1;Array subscript Count
num[0] =1;Array first bit save 1



for (int i =2,nloc=0;i<=100;i++)Multiply starting from 2
{
temp=0,carry_=0;Small table Initialization product initialization carry initialization

for (Int J =0;j<num_n;j++)
{
temp = num[j] * i + carry_;Current array value x factorial current value + carry number
NUM[J] = temp%10;//greater than 10 take low
Carry_ = temp/10; //greater than 10 take high
}
if (carry_> 0) //in 15 factorial there are two digits but only one
// Use this to make two bits all saved
{
Num[num_n] = carry_% 10;
Carry_ = carry_/10;
num_n++;
if (Carry_>0)
{
Num[num_n] = carry_% 10;
Carry_ = temp/10;
num_n++;
}
}
}
//print

while (num_n)
{
cout << num[num_n-1]; //under bidding clubs refers to the output number of the previous bit to minus 1 otherwise it will be played 0
num_n--;
}


} /span>

Large number factorial (100!)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.