献丑了,贴上我的算法。。
#include <stdio.h>
#include <conio.h>
/*
-- Program detail -----------
Programmer : yuki
Last modify date: 2005-10-29
-----------------------------
*/
/*
NOTICE: If you want to placed this code to another bbs, please note the origin
*/
/* Macro definition as buffer size */
#define BUFFER_SIZE 3000
#define DELIMITER_WIDTH 4
/* Holding the result */
static int array[BUFFER_SIZE] = {0};
/* Holding the data length */
static int vaild_bit = 1;
int main() {
int N;
printf("Input N = ");
scanf("%d",&N);
/* Judge the data which inputed by user */
if(N < 0 || N > 1000) {
printf("Impossible!\n");
getch();
return 0;
}
else {
/* Set the base number as 1 */
array[0] = 1;
/* Integer varible i and j functioned as counter, temp using to calc */
register int i = 1,j,temp;
/* General mutiplication */
while(i <= N) {
for(j = 0; j < vaild_bit; ++j) array[j] *= i;
for(j = 0; j < vaild_bit; ++j) {
if(array[j] < 10 && j == vaild_bit-1) break;
else if(array[j] < 10) continue;
temp = array[j];
array[j] = temp % 10;
array[j+1] += temp / 10;
/* Extend a bit for a new result */
if( array[j+1] >= 10 && j == vaild_bit-1 ) ++vaild_bit;
}
/* Reset the length of new data */
vaild_bit = j + 1;
++i;
}
/* Result published */
printf("%d!(%d bit(s)) = \n",N,vaild_bit);
for( i = vaild_bit - 1; i >= 0; --i ) {
printf("%d",array[i]);
/* Every four figures delimited by a space */
if(!(i % DELIMITER_WIDTH)) putch(0x20);
}
printf("\n");
getch();
}
return 0;
}