Cod sursa(job #2191026)

Utilizator dzNaLxDzen Alex dzNaLx Data 1 aprilie 2018 13:05:07
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g ("fact.out");
int factorial(int n)
{
    if(n==0)
        return 1;
    else
        return n*factorial(n-1);
}
int cifre0(int x)
{
    int nr=0;
    while(x>9)
    {
        if(x%10!=0)
            return nr;
        else
            nr++;
        x/=10;
    }
    return nr;
}
int main()
{
    int n,p;
    bool ok=false;
    f>>p;
    n=1;
    while(!ok)
    {
        if(cifre0(factorial(n))==p)
        {
            ok=true;
            g<<n;
        }
        else
            n++;
    }
    f.close();
    g.close();
    return 0;
}