Cod sursa(job #1517188)

Utilizator leonard.sfetcuLeonard leonard.sfetcu Data 3 noiembrie 2015 22:29:35
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>


FILE *f, *g;
long int factorial(long int i)

{if ((i == 0) ||( i == 1))
		return 1;
	else
		return i*factorial(i - 1);
}
int cifre(int x)
{
	int nr = 0;
	while (x)
	{
		
		if (x % 10 == 0)
		{
			nr++;
			x = x / 10;
		}
		else
			break;


	}
	return nr;

}

int main()
{
long int p,n=1,ok=0;
	f = fopen("fact.in", "r");
	g = fopen("fact.out", "w");
	fscanf(f, "%ld", &p);

	while (ok == 0)
	{
		if (cifre(factorial(n)) == p)
			ok = 1;
		else ++n;
	}
	fprintf(g,"%ld", n);
	
	



	return 0;
}