You are on page 1of 2

//��������� ����� � ��������� ����� � ������������ ������.

#include<iostream>
#include<fstream>

using namespace std;

//void output(int *mass);


int FACT(int *mass, int x, int SIZE);
void nameGen(int x, int *mass);
char *IntToChar(int n, char *s);

const int MAX_SIZE = 99999;


int SIZE = 1;

int main() {
setlocale(LC_ALL, "rus");
int mass[MAX_SIZE]; mass[0] = 1;
cout << "������� �����, ��������� �������� ����� �����: " << endl;
int fact; cin >> fact;
for (int i = 1; i <= fact; i++)
SIZE = FACT(mass, i, SIZE);
nameGen(fact, mass);//output(mass);
system("pause");
return NULL;
}

/*void output(int *mass) {


for (int i = SIZE - 1; i >= 0; i--)
cout << mass[i];
}*/

int FACT(int *mass, int x, int SIZE)


{
int SAVE;
int SAVE_0 = 0;
int i = 0;
while (i < SIZE) {
SAVE = mass[i] * x + SAVE_0;
SAVE_0 = SAVE / 10;
mass[i] = SAVE % 10;
i++;
}
while (SAVE_0) {
mass[SIZE] = SAVE_0 % 10;
SAVE_0 /= 10;
SIZE++;
}
return SIZE;
}

void nameGen(int x, int *mass) {


char str[MAX_SIZE];
IntToChar(x, str);
char newname[MAX_SIZE] = "fact_";
char format[MAX_SIZE] = ".txt";
strcat(newname, str);
strcat(newname, format);
ofstream fout;
fout.open((char*)newname, ios_base::out);
for (int i = SIZE - 1; i >= 0; i--)
fout << mass[i];
}

char *IntToChar(int n, char *s) {


char *t = s;
int z = 0;
if (n < 0) {
z = 1;
n = -n;
}
do *s++ = n % 10 + '0';
while (n /= 10);
if (z) *s++ = '-';
*s = '\0';
return strrev(t);
}

You might also like