NYOJ-28: factorial of large numbers

Source: Internet
Author: User
Description We all know how to calculate the factorial of a number, but if the number is large, how do we compute it and output it. Enter an integer m (0<m<=5000) output of the factorial of M, and enter a newline character sample input After the end of the output.
50
Sample output
30414093201713378043612608166064768844377641568960512000000000000 

#include <stdio.h>
#include <string.h>
#define N 20000/
* Array can not open too large, timeout, also can not open too small, small WA. *
/int fac[n];

int main ()
{
	int s,m,flag=0;
	scanf ("%d", &m);
	
	memset (fac,0,sizeof (FAC));
	int i,j;
	Fac[0] = 1;
	for (i=2;i<=m;i++)
	{
		flag = 0;
		for (j=0;j<n;j++)
		{
			s = fac[j]*i + flag;//flag to carry flag
			fac[j] = s%10;
			flag = S/10;
		}
	for (j = n-1;j>=0;j--)
		if (fac[j]) break;//Remove leading 0
	for (; j>=0;j--) printf ("%d", fac[j));
	printf ("\ n");
	return 0;
}


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.