Cod sursa(job #1097740)

Utilizator terrorturtle01Ion George Mihai terrorturtle01 Data 3 februarie 2014 21:38:29
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
using namespace std;

int P, N = 99999, c = 0, cif;
long f;

int fx(int n){
    if(n == 0){
        return 1;
    }else{
        return(n * fx(n - 1));
    }
}

int find_N(){
    int x = 0;
    while(N == 99999){
    f = fx(x);
    while(f != 0){
        cif = f%10;
        f = f/10;
        if(cif == 0){
            c++;
        }
        while(cif == 0){
            cif = f%10;
            f = f/10;
            c++;
        }
    }
    if(c == P){
        if(x < N){
        N = x;
        }
    }
    x++;
    }
    return N;
}

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>P;
    g<<find_N();
}