Cod sursa(job #602850)
| Utilizator | Data | 13 iulie 2011 14:40:54 | |
|---|---|---|---|
| Problema | Factorial | Scor | 15 |
| Compilator | c | Status | done |
| Runda | Arhiva de probleme | Marime | 0.45 kb |
#include<stdio.h>
int fac(int n) {
if ( n == 0 )
return 1;
else return n*fac(n-1);
}
int main(){
int n=0,p,i,k=0;
int res=0;
FILE *in,*out;
in = fopen("fact.in","r");
fscanf(in,"%d",&p);
if (p !=0){
for (i=5;n<=p;i+=5){
k=i;
while(k%5==0){
n+=1;
k=k/5;
}
}
if(n!=p)
res = -1;
else res=i;
}
else res=1;
fclose(in);
out = fopen("fact.out","w");
fprintf(out,"%d",res);
fclose(out);
return 0;
}