Cod sursa(job #2020344)

Utilizator speedylawl1Cota Calin speedylawl1 Data 9 septembrie 2017 21:56:31
Problema Factorial Scor 45
Compilator c Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cinci(int n)
{
	int cont = 0;

	while (n % 5 == 0)
	{
		cont++;
		n /= 5;
	}

	return cont;
}

int factorial(int a)
{
	int zero = 0;
	int i = 0;

	while (1)
	{
		if (zero > a)
		{
			return -1;
		}
		if (zero == a)
		{
			return i;
		}

		i += 5;
		if (i % 5 == 0)
		{
			zero += cinci(i);
		}

	}
}

int main()
{
	FILE *f, *g;
	int res, a;


	f = fopen("fact.in", "r");
	g = fopen("fact.out", "w");
	if (NULL == f)
	{
		return 0;
	}
	if (NULL == g)
	{
		return 0;
	}

	fscanf(f, "%d", &a);
	
	res = factorial(a);

	fprintf(g, "%d", res);
	
	fclose(f);
	fclose(g);

	return 0;
}