add task3
This commit is contained in:
parent
3447f9e4f3
commit
ae064e728c
2
lab19/lab19/in3.txt
Normal file
2
lab19/lab19/in3.txt
Normal file
@ -0,0 +1,2 @@
|
||||
1000
|
||||
21 27 14 20 9 -16 -2 -2 2 24 -15 -15 -19 7 -19 -9 35 -18 7 16 31 4 -18 13 32 2 1 36 18 15 27 -14 -9 -2 -11 32 27 -1 35 34 3 31 -18 13 13 24 1 11 33 8 27 24 2 37 37 -1 3 1 29 38 -4 15 30 22 28 26 20 -18 -16 8 6 25 30 -11 -10 30 -14 1 13 -12 -11 3 4 14 16 0 26 36 -9 8 4 19 6 23 -3 38 18 22 -11 21 13 15 -1 -2 4 10 37 6 33 -14 21 -15 24 32 10 -11 -3 13 37 -8 26 10 21 16 15 27 -5 14 -9 32 30 -10 1 -16 26 -10 7 -9 -13 37 17 27 13 -17 -15 9 29 18 21 28 -18 26 6 -10 13 -12 -20 -9 22 15 -10 39 4 -3 -12 -17 35 1 -18 30 11 36 -6 20 16 1 28 19 28 -16 -19 34 33 -1 -2 18 -20 -12 -13 27 -12 -7 28 23 27 1 10 -3 -7 14 9 36 15 31 0 9 -1 36 38 -17 24 8 4 9 29 -18 -5 5 13 -17 23 7 14 3 -12 -20 -2 -2 -20 36 18 21 9 18 29 17 -8 22 38 32 18 39 -10 -3 18 -9 -5 8 -4 31 -18 34 12 -5 28 6 2 6 15 33 29 22 4 16 21 -2 -18 31 -19 39 -3 16 32 9 15 12 0 30 -17 29 21 28 1 -11 -5 23 2 5 -18 5 8 26 37 37 32 12 9 34 21 9 36 -11 8 -8 -15 35 -6 29 -19 12 5 -20 38 13 39 -17 -1 -4 -13 29 29 17 -14 29 -7 15 37 -4 6 5 -12 2 15 34 34 -19 36 11 6 3 33 35 25 -7 -8 -12 12 -15 33 16 -19 38 -14 2 -19 -16 16 -18 29 -19 -5 30 -7 6 24 39 -8 19 13 24 34 30 -15 -11 26 13 14 -18 -12 18 -13 -15 -2 -9 -18 5 -3 14 -6 4 34 -6 -8 39 -7 30 27 17 -2 -3 -7 30 3 8 12 -15 22 0 33 -13 -18 -1 27 25 23 -16 23 12 21 1 23 -8 25 33 25 -9 12 2 -18 6 24 20 27 0 13 -6 30 -10 35 33 11 0 36 27 5 -10 0 -6 35 4 39 5 36 14 18 2 11 6 38 13 11 24 38 4 39 32 20 7 20 -14 -10 -3 -10 15 16 27 23 -2 4 -11 2 26 25 -13 37 -6 25 -13 29 -12 23 0 -18 2 -17 36 -3 -19 35 -15 -16 20 2 -4 30 26 11 31 31 27 13 20 10 24 -12 23 0 11 -18 9 -20 -7 38 38 5 27 -3 -20 -2 -1 3 20 17 24 37 -12 33 -13 -19 30 -20 28 13 4 5 -20 11 4 35 -4 -8 -10 23 5 16 36 -14 37 -14 17 37 31 29 1 36 -18 17 12 37 16 -15 21 -17 -11 29 -15 -1 32 16 15 33 22 24 14 34 32 17 9 12 3 7 3 -9 35 27 28 35 18 -17 -18 34 11 -19 -5 19 -15 21 30 -14 -6 5 23 10 38 -1 1 -7 -6 -3 -6 16 -7 16 5 -18 28 21 -20 -7 1 35 -5 -18 -18 -9 17 4 18 -8 3 16 -7 0 -7 15 12 18 -10 37 32 12 15 9 -9 -20 8 -15 -10 37 -11 -10 5 13 34 31 20 4 18 15 39 12 25 -16 -19 -17 29 -5 8 -8 37 9 16 -19 -13 27 1 9 20 13 -6 1 -3 35 23 33 32 4 1 32 19 10 8 -13 -16 35 -14 -2 -10 27 7 4 3 21 23 -14 3 -10 11 -11 -20 24 22 39 13 11 24 -2 32 10 -15 35 19 -17 2 18 7 4 8 11 24 33 15 -15 12 6 -2 9 2 39 -15 9 24 25 -20 5 -12 38 10 -19 -17 -8 32 12 -13 -10 -17 1 -17 3 27 0 9 15 25 8 -17 7 28 -17 17 9 -17 -11 -19 8 -18 -12 0 21 -2 -6 -12 26 10 9 -17 -10 -20 8 -13 16 3 15 -14 -15 -2 -7 -11 -16 8 -17 39 17 26 4 -5 18 6 11 5 -5 21 29 -4 24 15 4 -18 15 13 -18 36 28 32 6 6 -7 -11 -16 25 26 32 35 13 -15 -4 16 21 14 34 16 32 36 38 2 15 -5 31 30 1 25 11 37 26 -10 10 2 14 13 13 36 -8 8 -18 13 34 23 -6 3 16 8 4 -3 -7 29 8 20 0 -2 38 30 15 21 4 3 -4 -17 9 2 1 29 28 2 13 -6 -20 -18 3 31 29 18 19 28 39 11 -17 25 -19 24 12 25 33 18 -11 -18 38 -3 30 1 34 8 -19 39 -7 -5 -11 17 -11 38 -20 31 24 37 -5 -5 -5 10 19 12 -12 -18 14 -15 -10 -16 34 20 35 11 -19 35 39 -10 18 13 -12 17 -8 -4 -11 -7 28 21 -10 23 -17 8 24 38 -20 11 5 -6 31 33 -13 33 -5 -12 -15 -4 9 10 -2 -11 -7 -14 0 16 -11
|
@ -131,6 +131,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="data.txt" />
|
||||
<Text Include="in3.txt" />
|
||||
<Text Include="out3.txt" />
|
||||
<Text Include="tasks12.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -26,5 +26,11 @@
|
||||
<Text Include="tasks12.txt">
|
||||
<Filter>Файлы ресурсов</Filter>
|
||||
</Text>
|
||||
<Text Include="in3.txt">
|
||||
<Filter>Файлы ресурсов</Filter>
|
||||
</Text>
|
||||
<Text Include="out3.txt">
|
||||
<Filter>Файлы ресурсов</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -75,7 +75,7 @@ void save(int arr[], int len, char filename[]) {
|
||||
|
||||
void saveRandomArray() {
|
||||
int len = 1000;
|
||||
char filename[] = "out3.txt";
|
||||
char filename[] = "in3.txt";
|
||||
|
||||
int* parr;
|
||||
parr = (int*)malloc(sizeof(int) * len);
|
||||
@ -85,7 +85,7 @@ void saveRandomArray() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
parr[i] = rand() % 60 - 30;
|
||||
parr[i] = rand() % 60 - 20;
|
||||
}
|
||||
|
||||
save(parr, len, filename);
|
||||
@ -104,7 +104,7 @@ void dotasks12(int arr[], int len) {
|
||||
}
|
||||
|
||||
int* parr;
|
||||
parr = (int*)malloc(sizeof(int) * count);
|
||||
parr = (int*)malloc(sizeof(int) * (count + 1));
|
||||
if (parr == NULL) {
|
||||
printf_s("Not enough memory\n");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -121,8 +121,46 @@ void dotasks12(int arr[], int len) {
|
||||
save(parr, count, "tasks12.txt");
|
||||
}
|
||||
|
||||
void task3() {
|
||||
int* arr;
|
||||
int len = load(&arr, "in3.txt");
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sum += arr[i];
|
||||
}
|
||||
double average = (double)sum / len;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if ((arr[i] > 0) && (arr[i] < average)) count++;
|
||||
}
|
||||
|
||||
int* parr;
|
||||
parr = (int*)malloc(sizeof(int) * (count + 1));
|
||||
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] > 0) && (arr[i] < average)) {
|
||||
parr[j] = arr[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
save(parr, count, "out3.txt");
|
||||
}
|
||||
|
||||
int main() {
|
||||
saveRandomArray();
|
||||
//saveRandomArray();
|
||||
|
||||
// task 1
|
||||
/*int fixarr[1000];
|
||||
int flen = loadToFixedArray(fixarr, 1000, "data.txt");
|
||||
dotasks12(fixarr, flen);*/
|
||||
|
||||
// task 2
|
||||
//int* parr;
|
||||
@ -130,11 +168,7 @@ int main() {
|
||||
//dotasks12(parr, len);
|
||||
//printarr(parr, len);
|
||||
|
||||
|
||||
// task 1
|
||||
/*int fixarr[1000];
|
||||
int flen = loadToFixedArray(fixarr, 1000, "data.txt");
|
||||
dotasks12(fixarr, flen);*/
|
||||
task3();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,2 +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
|
||||
139
|
||||
2 7 7 4 2 1 3 1 8 2 3 1 8 6 1 3 4 8 4 6 4 6 1 7 6 4 1 1 1 8 4 5 7 3 8 6 2 6 4 1 2 5 5 8 8 5 6 5 2 6 3 2 6 5 4 3 8 1 2 6 5 4 5 2 6 4 7 4 2 2 2 5 3 4 5 4 5 1 3 7 3 5 1 5 1 4 3 8 5 4 8 1 1 4 1 8 7 4 3 3 2 7 4 8 6 2 5 1 3 8 7 8 8 3 8 4 6 5 4 6 6 2 1 2 8 3 8 4 8 4 3 2 1 2 3 1 8 8 5
|
Loading…
Reference in New Issue
Block a user