Cod sursa(job #2599766)

Utilizator PMI13Pop Marius Ionut PMI13 Data 11 aprilie 2020 18:54:47
Problema Factorial Scor 35
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>
#include <stdlib.h>

int fact (int p)
{
    int n = 0 , x;

    if( p == 0 )
        return 1;

    while(p > 0)
    {
        n += 5;
        x = n;
        while( x % 5 == 0)
        {
            x /= 5;
            p--;
        }
    }

    if(p == -1)
        return p;

    return n;
}

int main()
{
    int p, n;

    FILE *fp = fopen("fact.in","r");
    fscanf(fp ,"%d" , &p);
    fclose(fp);

    n = fact(p);

    FILE *fi = fopen("fact.out" , "w");
    fprintf(fi , "%d" , n);
    fclose(fi);

    return 0;
}