Cod sursa(job #93550)

Utilizator cristian_alex_81cristian alexandru cristian_alex_81 Data 19 octombrie 2007 08:47:44
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <stdio.h>
#include <math.h>

//--------------------

FILE * f=fopen ("fact.in","r");
FILE * g=fopen ("fact.out","w");
long int p,nr,ct;
//--------------------
void cit()
{
fscanf (f,"%ld",&p);
}
//--------------------
void tip()
{
fprintf (g,"%ld",nr-1);
}
//--------------------
void verific(int &ok, long int fact)
{
int cif=0;
ct=0;

	while ((fact>0)&&(cif==0))
	{
	 cif=fact%10;
	 fact=fact/10;
		if (cif==0)
		{
		ct++;
		}
	}
	if (ct==p)
	{
	ok=1;
	}
}
//--------------------
void factor()
{
int ok;
long int fact;

	if(p==0)
	{
	nr=1;
	tip();
	}
	else
	{
	nr=2;
	fact=1;
	ok=0;
		while(!ok)
		{
		fact=fact*nr;
		nr++;
			verific(ok,fact);
		}
		tip();
	}
}
//--------------------
int main()
{
cit();
factor();
fclose(f);
fclose(g);
return 0;
}
//--------------------