Cod sursa(job #2599790)

Utilizator PMI13Pop Marius Ionut PMI13 Data 11 aprilie 2020 19:05:32
Problema Factorial Scor 10
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <stdio.h>
#include <stdlib.h>

int fact (int p)
{
    int n = 5, x = 25 , s ;

    if( p == 0 )
        return 1;

    n *= p;
    while( x < n)
    {
        s = n % x;
        s *= 5;
        n = n - 5;
        x *= 5;
    }

    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;
}