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5 3 5 3 3 3 4 2 5 2 3 5 5 5 4 5 2 2 4 4 3 4 2 4 2 5 5 3 5 5 4 4 3 2 3 2 2 3 3 2 3 4 5 5 2 2 4 2 5 3 4 5 3 5 3 5 2 3 2 3 4 4 3 3 4 2 2 3
|
@ -129,6 +129,10 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.c" />
|
<ClCompile Include="main.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="data.txt" />
|
||||||
|
<Text Include="tasks12.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -19,4 +19,12 @@
|
|||||||
<Filter>Исходные файлы</Filter>
|
<Filter>Исходные файлы</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="data.txt">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</Text>
|
||||||
|
<Text Include="tasks12.txt">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</Text>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -9,10 +9,33 @@ void printarr(int arr[], int len) {
|
|||||||
printf("\b\b]\n");
|
printf("\b\b]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int loadToFixedArray(int arr[], int len, char filename[]) {
|
||||||
|
FILE* file = fopen(filename, "r");
|
||||||
|
if (file == NULL) {
|
||||||
|
puts("File not found");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int flen;
|
||||||
|
fscanf_s(file, "%d", &flen);
|
||||||
|
if (flen > len) {
|
||||||
|
puts("Dataset if too big");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < flen; i++) {
|
||||||
|
fscanf_s(file, "%d", &arr[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
return flen;
|
||||||
|
}
|
||||||
|
|
||||||
int load(int** parr, char filename[]) {
|
int load(int** parr, char filename[]) {
|
||||||
FILE* file = fopen(filename, "r");
|
FILE* file = fopen(filename, "r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
puts("Ôàéë íå íàéäåí");
|
puts("File not found");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +60,7 @@ int load(int** parr, char filename[]) {
|
|||||||
void save(int arr[], int len, char filename[]) {
|
void save(int arr[], int len, char filename[]) {
|
||||||
FILE* file = fopen(filename, "w");
|
FILE* file = fopen(filename, "w");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
puts("Íå óäàëîñü ñîçäàòü ôàéë");
|
puts("Failed to create file");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,27 +73,68 @@ void save(int arr[], int len, char filename[]) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveRandomArray(int len, char filename[]) {
|
void saveRandomArray() {
|
||||||
|
int len = 1000;
|
||||||
|
char filename[] = "out3.txt";
|
||||||
|
|
||||||
int* parr;
|
int* parr;
|
||||||
parr = (int*)malloc(sizeof(int) * len);
|
parr = (int*)malloc(sizeof(int) * len);
|
||||||
if (parr == NULL) {
|
if (parr == NULL) {
|
||||||
printf_s("Not enough memory to load data\n");
|
printf_s("Not enough memory\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
parr[i] = rand() % 6;
|
parr[i] = rand() % 60 - 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
save(parr, len, filename);
|
save(parr, len, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
void dotasks12(int arr[], int len) {
|
||||||
int* parr;
|
int sum = 0;
|
||||||
int len;
|
for (int i = 0; i < len; i++) {
|
||||||
//saveRandomArray(30, "data.txt");
|
sum += arr[i];
|
||||||
len = load(&parr, "data.txt");
|
}
|
||||||
|
int average = sum / len;
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (arr[i] > average) count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int* parr;
|
||||||
|
parr = (int*)malloc(sizeof(int) * count);
|
||||||
|
if (parr == NULL) {
|
||||||
|
printf_s("Not enough memory\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (arr[i] > average) {
|
||||||
|
parr[j] = arr[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
save(parr, count, "tasks12.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
saveRandomArray();
|
||||||
|
|
||||||
|
// task 2
|
||||||
|
//int* parr;
|
||||||
|
//int len = load(&parr, "data.txt");
|
||||||
|
//dotasks12(parr, len);
|
||||||
|
//printarr(parr, len);
|
||||||
|
|
||||||
|
|
||||||
|
// task 1
|
||||||
|
/*int fixarr[1000];
|
||||||
|
int flen = loadToFixedArray(fixarr, 1000, "data.txt");
|
||||||
|
dotasks12(fixarr, flen);*/
|
||||||
|
|
||||||
printarr(parr, len);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
2
lab19/lab19/out3.txt
Normal file
2
lab19/lab19/out3.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1000
|
||||||
|
11 17 4 10 -1 -26 -12 -12 -8 14 -25 -25 -29 -3 -29 -19 25 -28 -3 6 21 -6 -28 3 22 -8 -9 26 8 5 17 -24 -19 -12 -21 22 17 -11 25 24 -7 21 -28 3 3 14 -9 1 23 -2 17 14 -8 27 27 -11 -7 -9 19 28 -14 5 20 12 18 16 10 -28 -26 -2 -4 15 20 -21 -20 20 -24 -9 3 -22 -21 -7 -6 4 6 -10 16 26 -19 -2 -6 9 -4 13 -13 28 8 12 -21 11 3 5 -11 -12 -6 0 27 -4 23 -24 11 -25 14 22 0 -21 -13 3 27 -18 16 0 11 6 5 17 -15 4 -19 22 20 -20 -9 -26 16 -20 -3 -19 -23 27 7 17 3 -27 -25 -1 19 8 11 18 -28 16 -4 -20 3 -22 -30 -19 12 5 -20 29 -6 -13 -22 -27 25 -9 -28 20 1 26 -16 10 6 -9 18 9 18 -26 -29 24 23 -11 -12 8 -30 -22 -23 17 -22 -17 18 13 17 -9 0 -13 -17 4 -1 26 5 21 -10 -1 -11 26 28 -27 14 -2 -6 -1 19 -28 -15 -5 3 -27 13 -3 4 -7 -22 -30 -12 -12 -30 26 8 11 -1 8 19 7 -18 12 28 22 8 29 -20 -13 8 -19 -15 -2 -14 21 -28 24 2 -15 18 -4 -8 -4 5 23 19 12 -6 6 11 -12 -28 21 -29 29 -13 6 22 -1 5 2 -10 20 -27 19 11 18 -9 -21 -15 13 -8 -5 -28 -5 -2 16 27 27 22 2 -1 24 11 -1 26 -21 -2 -18 -25 25 -16 19 -29 2 -5 -30 28 3 29 -27 -11 -14 -23 19 19 7 -24 19 -17 5 27 -14 -4 -5 -22 -8 5 24 24 -29 26 1 -4 -7 23 25 15 -17 -18 -22 2 -25 23 6 -29 28 -24 -8 -29 -26 6 -28 19 -29 -15 20 -17 -4 14 29 -18 9 3 14 24 20 -25 -21 16 3 4 -28 -22 8 -23 -25 -12 -19 -28 -5 -13 4 -16 -6 24 -16 -18 29 -17 20 17 7 -12 -13 -17 20 -7 -2 2 -25 12 -10 23 -23 -28 -11 17 15 13 -26 13 2 11 -9 13 -18 15 23 15 -19 2 -8 -28 -4 14 10 17 -10 3 -16 20 -20 25 23 1 -10 26 17 -5 -20 -10 -16 25 -6 29 -5 26 4 8 -8 1 -4 28 3 1 14 28 -6 29 22 10 -3 10 -24 -20 -13 -20 5 6 17 13 -12 -6 -21 -8 16 15 -23 27 -16 15 -23 19 -22 13 -10 -28 -8 -27 26 -13 -29 25 -25 -26 10 -8 -14 20 16 1 21 21 17 3 10 0 14 -22 13 -10 1 -28 -1 -30 -17 28 28 -5 17 -13 -30 -12 -11 -7 10 7 14 27 -22 23 -23 -29 20 -30 18 3 -6 -5 -30 1 -6 25 -14 -18 -20 13 -5 6 26 -24 27 -24 7 27 21 19 -9 26 -28 7 2 27 6 -25 11 -27 -21 19 -25 -11 22 6 5 23 12 14 4 24 22 7 -1 2 -7 -3 -7 -19 25 17 18 25 8 -27 -28 24 1 -29 -15 9 -25 11 20 -24 -16 -5 13 0 28 -11 -9 -17 -16 -13 -16 6 -17 6 -5 -28 18 11 -30 -17 -9 25 -15 -28 -28 -19 7 -6 8 -18 -7 6 -17 -10 -17 5 2 8 -20 27 22 2 5 -1 -19 -30 -2 -25 -20 27 -21 -20 -5 3 24 21 10 -6 8 5 29 2 15 -26 -29 -27 19 -15 -2 -18 27 -1 6 -29 -23 17 -9 -1 10 3 -16 -9 -13 25 13 23 22 -6 -9 22 9 0 -2 -23 -26 25 -24 -12 -20 17 -3 -6 -7 11 13 -24 -7 -20 1 -21 -30 14 12 29 3 1 14 -12 22 0 -25 25 9 -27 -8 8 -3 -6 -2 1 14 23 5 -25 2 -4 -12 -1 -8 29 -25 -1 14 15 -30 -5 -22 28 0 -29 -27 -18 22 2 -23 -20 -27 -9 -27 -7 17 -10 -1 5 15 -2 -27 -3 18 -27 7 -1 -27 -21 -29 -2 -28 -22 -10 11 -12 -16 -22 16 0 -1 -27 -20 -30 -2 -23 6 -7 5 -24 -25 -12 -17 -21 -26 -2 -27 29 7 16 -6 -15 8 -4 1 -5 -15 11 19 -14 14 5 -6 -28 5 3 -28 26 18 22 -4 -4 -17 -21 -26 15 16 22 25 3 -25 -14 6 11 4 24 6 22 26 28 -8 5 -15 21 20 -9 15 1 27 16 -20 0 -8 4 3 3 26 -18 -2 -28 3 24 13 -16 -7 6 -2 -6 -13 -17 19 -2 10 -10 -12 28 20 5 11 -6 -7 -14 -27 -1 -8 -9 19 18 -8 3 -16 -30 -28 -7 21 19 8 9 18 29 1 -27 15 -29 14 2 15 23 8 -21 -28 28 -13 20 -9 24 -2 -29 29 -17 -15 -21 7 -21 28 -30 21 14 27 -15 -15 -15 0 9 2 -22 -28 4 -25 -20 -26 24 10 25 1 -29 25 29 -20 8 3 -22 7 -18 -14 -21 -17 18 11 -20 13 -27 -2 14 28 -30 1 -5 -16 21 23 -23 23 -15 -22 -25 -14 -1 0 -12 -21 -17 -24 -10 6 -21
|
2
lab19/lab19/tasks12.txt
Normal file
2
lab19/lab19/tasks12.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
474
|
||||||
|
5 4 4 4 4 5 5 5 4 5 5 4 4 4 5 5 4 5 4 5 5 5 4 5 5 4 5 5 4 5 5 4 5 4 4 4 4 4 4 4 4 4 5 4 4 5 5 4 5 4 4 4 5 5 4 4 4 4 4 4 4 5 5 5 4 5 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 5 4 5 5 5 4 4 5 4 5 4 5 4 4 5 5 5 5 4 4 5 5 5 4 5 4 5 5 5 5 4 5 4 4 4 4 4 4 4 5 4 4 5 5 5 4 4 5 4 4 4 5 4 4 4 5 5 5 4 5 5 5 4 4 4 4 5 4 4 5 5 5 5 4 5 4 4 5 4 4 5 4 5 5 4 4 4 4 5 4 4 5 5 4 4 4 4 4 4 5 4 5 4 4 4 4 4 5 4 5 4 4 5 4 5 4 5 5 5 5 5 5 4 4 4 5 4 4 4 5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