Cod sursa(job #2453181)

Utilizator cristi1990anCornea Cristian cristi1990an Data 2 septembrie 2019 18:26:45
Problema Factorial Scor 15
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

unsigned int save_tens(unsigned long *p)
{
	unsigned int nr = 0;

	while (*p % 10 == 0)
	{
		*p = *p / 10;
		nr++;
	}
	return nr;
}

int main()
{
	FILE* f = fopen("fact.in", "rt");
	unsigned long n, p=1, i=2, count=0;
	
	fscanf(f, "%lu", &n);

	while (count != n)
	{
		p = (p * i);
		p = p % 100000000;
		count = count + save_tens(&p);
		i++;
		printf("%lu %lu \n", p, count);
	}

	f = fopen("fact.out", "wt");

	fprintf(f, "%lu \n", i-1);
	fflush(stdout);

	fclose(f);
	system("pause");
	return 0;
}