# Program code for implementing N factorial in C Language

Source: Internet
Author: User

The Code is as follows: Copy codeThe Code is as follows: # include <stdio. h>
# Include <stdlib. h>
# Define N 10 // calculate the factorial of N
Int main ()
{// Array 1-digit 1!
Int ary [N] = {1, 1 };
Int I, j;
For (I = 2; I <= N; I ++)
{
// Factorial of each lower mark. The 0th-bit subscript is the number of digits, so it starts from 1st bits.
For (j = 1; j <= ary [0]; j ++)
{
Ary [j] = ary [j] * I;
}
// Handle the carry problem by one second
For (j = 1; j <= ary [0]; j ++)
{
If (ary [j]> = 10000)
{
// Carry
Ary [j + 1] = ary [j + 1] + ary [j]/10000;
// After carrying, only the remainder is left.
Ary [j] = ary [j] % 10000;
}
}
// If there is an increment, the number of digits is + 1
// Here j is already a bit larger than 1
If (ary [j]> = 1)
{
Ary [0] ++;
}
}

// Inverted output
For (j = ary [0]; j> 0; j --)
{
Printf ("% d", ary [j]);
}
Printf ("\ r \ n ");
Return 0;
}

Related Keywords:

### 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.