Skip to content

Instantly share code, notes, and snippets.

@eternaltung
Created February 6, 2014 12:47
Show Gist options
  • Save eternaltung/8843528 to your computer and use it in GitHub Desktop.
Save eternaltung/8843528 to your computer and use it in GitHub Desktop.
using System;
namespace FactorialArray
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int[] num = new int[n];
int digit = 1; //位數
num[0] = 1;
for (int i = 1; i <= n; i++)
{
//所有位數都要乘
for (int j = 0; j < n; j++)
num[j] *= i;
for (int k = 0; k < n - 1; k++)
{
//超過個位數字時要進位
if (num[k] > 9)
{
num[k + 1] = num[k + 1] + num[k] / 10;
num[k] = num[k] % 10;
}
}
}
//查看有幾位數
for (int i = n - 1; i >= 0; i--)
{
if (num[i] != 0)
{
digit = i + 1;
break;
}
}
//印出結果
Console.Write(n + "!=");
for (int i = digit - 1; i >= 0; i--)
Console.Write(num[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment