568 - Just the Facts

#include<stdio.h>
#include<string.h>
#include<iostream>
#define MAX 10010
using namespace std;
int arr[MAX];
int main()
{
    int n,i,mod,temp;
    while(scanf("%d",&n)==1)
    {
        if(n==0)
        {
            printf("%5d -> 1\n",n);
            continue;
        }
        arr[1]=1;
        for(i=2;i<=n;i++)
        {
            temp=arr[i-1]*i;
            while(temp%10==0)
            {
                temp=temp/10;
            }
            temp=temp%100000;
            arr[i]=temp;
        }
        mod=arr[n]%10;
        printf("%5d -> %d\n",n,mod);
        memset(arr,0,sizeof(arr));
    }
return 0;
}

0 comments: (+add yours?)