c·c++/c++ 프로그래밍

100! 구하기 0000 을 출력하기(만 팩토리얼까지 구하기)

바로이순간 2012. 3. 26. 22:40

#include<iostream>

using namespace std;

#define T 10000


int main() {

  int arr[T] = {1,};


  int i,j;

  int temp=0;

  int m,fac;


  char ch;

  cout << "정수를 입력하세요" << endl;

  cin >> fac;


  for(i=1; i<=fac; i++) {

    temp=0;

    for(j=0; j<T; j++) {

      arr[j]=arr[j]*i + temp;

      temp=arr[j]/10000;

      arr[j]=arr[j]-10000*temp;

    }

  }


  i=T-1;

  while(arr[i]==0)i=i-1;

  cout << fac << "!은 "<<endl;


  cout<<arr[i]; i-=1;

  while(i>-1) { cout.fill('0'); cout.width(4); cout << arr[i]; i-=1;}

  cout << " 입니다." << endl;


  return 0;

}


위의 프로그램은 10000! (만 팩토리얼)까지를 구할 수 있습니다.