From f2c98c712df3bdcc8e8ac6bf7d2b39a24ea2c77b Mon Sep 17 00:00:00 2001 From: Kaehvaman Date: Sat, 2 Nov 2024 11:06:38 +0400 Subject: [PATCH] finish task4 --- lab19/lab19/in4.txt | 2 ++ lab19/lab19/lab19.vcxproj | 3 ++ lab19/lab19/lab19.vcxproj.filters | 6 ++++ lab19/lab19/main.c | 50 +++++++++++++++++++++---------- lab19/lab19/out4.txt | 2 ++ 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 lab19/lab19/in4.txt create mode 100644 lab19/lab19/out4.txt diff --git a/lab19/lab19/in4.txt b/lab19/lab19/in4.txt new file mode 100644 index 0000000..acecad7 --- /dev/null +++ b/lab19/lab19/in4.txt @@ -0,0 +1,2 @@ +1000 +41000 67000 134000 100000 169000 124000 78000 158000 162000 64000 105000 145000 81000 27000 161000 91000 195000 142000 27000 36000 191000 4000 102000 153000 92000 182000 21000 116000 118000 95000 47000 126000 171000 138000 69000 112000 67000 99000 35000 94000 103000 11000 122000 133000 73000 64000 141000 111000 53000 68000 147000 44000 62000 157000 37000 59000 123000 141000 129000 178000 116000 35000 190000 42000 88000 106000 40000 142000 64000 48000 46000 5000 90000 129000 170000 150000 6000 101000 193000 148000 29000 23000 84000 154000 156000 40000 166000 176000 131000 108000 144000 39000 26000 123000 137000 138000 118000 82000 129000 141000 33000 115000 39000 58000 104000 130000 177000 106000 73000 186000 21000 145000 124000 72000 70000 29000 177000 173000 97000 112000 186000 90000 161000 36000 155000 167000 55000 174000 31000 52000 150000 150000 141000 124000 166000 30000 107000 191000 7000 137000 57000 87000 153000 183000 145000 109000 9000 158000 21000 188000 22000 146000 106000 30000 13000 168000 100000 191000 162000 55000 10000 159000 24000 137000 148000 83000 195000 41000 2000 150000 91000 36000 174000 20000 196000 21000 148000 199000 68000 84000 81000 134000 53000 199000 18000 138000 100000 188000 127000 67000 128000 93000 48000 83000 7000 21000 110000 17000 13000 114000 109000 16000 135000 51000 0 49000 119000 156000 198000 103000 24000 8000 44000 9000 189000 102000 195000 85000 93000 143000 123000 187000 114000 103000 48000 0 58000 18000 180000 196000 198000 81000 189000 198000 9000 157000 72000 22000 138000 92000 38000 179000 190000 57000 158000 191000 15000 88000 156000 111000 2000 34000 72000 55000 128000 46000 162000 86000 75000 33000 69000 142000 44000 16000 81000 198000 122000 51000 21000 99000 157000 76000 92000 189000 75000 112000 0 110000 3000 69000 61000 88000 1000 189000 55000 23000 2000 185000 182000 85000 88000 26000 17000 157000 32000 132000 169000 154000 121000 189000 176000 129000 168000 92000 25000 155000 34000 149000 41000 112000 145000 60000 118000 153000 139000 23000 79000 196000 87000 129000 149000 37000 66000 149000 193000 195000 97000 16000 86000 105000 88000 82000 55000 134000 114000 101000 116000 71000 186000 63000 113000 155000 185000 53000 112000 8000 32000 145000 113000 156000 121000 158000 46000 182000 81000 144000 196000 22000 129000 161000 135000 50000 173000 66000 44000 59000 92000 39000 53000 24000 154000 110000 145000 49000 186000 113000 74000 22000 168000 18000 187000 105000 158000 191000 2000 25000 77000 14000 114000 24000 134000 74000 172000 159000 33000 70000 87000 97000 118000 177000 173000 70000 163000 68000 192000 185000 102000 80000 13000 27000 2000 99000 127000 25000 143000 124000 23000 172000 61000 181000 3000 32000 105000 193000 125000 31000 92000 142000 22000 86000 64000 100000 187000 160000 13000 174000 70000 170000 35000 33000 111000 160000 96000 67000 85000 150000 140000 94000 95000 24000 19000 125000 176000 94000 58000 102000 171000 66000 78000 193000 51000 84000 18000 64000 119000 152000 0 87000 60000 126000 10000 157000 170000 115000 176000 27000 43000 158000 164000 109000 82000 86000 165000 87000 177000 74000 25000 27000 29000 128000 23000 120000 102000 162000 123000 196000 137000 61000 195000 125000 64000 60000 2000 116000 30000 126000 11000 171000 11000 147000 153000 120000 190000 124000 188000 163000 140000 51000 62000 29000 100000 113000 158000 178000 165000 7000 77000 0 58000 39000 103000 160000 157000 124000 77000 108000 113000 87000 1000 50000 60000 28000 193000 184000 5000 140000 111000 104000 35000 156000 72000 150000 23000 85000 156000 16000 26000 157000 126000 157000 137000 71000 69000 161000 96000 22000 17000 112000 117000 96000 185000 41000 23000 129000 29000 165000 159000 132000 96000 55000 53000 162000 184000 134000 54000 172000 57000 169000 132000 163000 7000 83000 111000 35000 67000 48000 75000 138000 23000 142000 154000 111000 141000 175000 59000 25000 21000 70000 26000 134000 5000 183000 50000 198000 79000 101000 193000 134000 37000 134000 156000 193000 176000 105000 162000 148000 81000 100000 13000 41000 55000 55000 142000 62000 11000 77000 24000 78000 152000 43000 96000 73000 40000 113000 75000 72000 18000 10000 17000 132000 112000 95000 169000 31000 40000 88000 85000 90000 97000 189000 190000 145000 153000 114000 51000 140000 44000 58000 135000 159000 192000 5000 64000 181000 103000 29000 175000 8000 92000 197000 149000 156000 161000 27000 67000 141000 129000 40000 13000 174000 1000 77000 15000 83000 13000 192000 24000 1000 192000 159000 70000 28000 27000 84000 75000 186000 98000 170000 87000 47000 4000 103000 21000 63000 106000 163000 10000 171000 89000 40000 164000 142000 19000 113000 191000 104000 18000 32000 150000 5000 175000 139000 103000 22000 98000 47000 184000 48000 171000 64000 113000 75000 145000 112000 146000 78000 169000 62000 119000 185000 89000 144000 65000 140000 45000 108000 118000 70000 1000 123000 132000 72000 152000 87000 170000 163000 101000 103000 23000 127000 0 169000 15000 165000 28000 143000 147000 88000 143000 37000 9000 63000 49000 81000 188000 142000 8000 60000 21000 158000 154000 88000 146000 90000 149000 43000 30000 20000 148000 67000 136000 183000 35000 26000 185000 38000 53000 29000 24000 148000 123000 159000 57000 166000 144000 155000 118000 126000 11000 25000 155000 1000 149000 96000 184000 115000 164000 142000 75000 113000 142000 196000 148000 72000 26000 6000 173000 29000 4000 105000 26000 12000 175000 93000 165000 36000 136000 141000 14000 194000 56000 52000 136000 38000 82000 155000 15000 131000 30000 41000 25000 11000 37000 186000 90000 50000 62000 34000 93000 153000 16000 52000 8000 62000 33000 54000 103000 34000 103000 56000 148000 124000 117000 13000 109000 28000 0 80000 118000 58000 50000 155000 161000 64000 103000 76000 43000 109000 102000 161000 89000 148000 82000 53000 74000 20000 2000 123000 31000 169000 78000 59000 8000 19000 171000 3000 145000 181000 104000 192000 85000 113000 98000 189000 122000 138000 37000 10000 61000 34000 108000 161000 159000 93000 115000 69000 137000 69000 58000 100000 171000 64000 117000 15000 155000 15000 130000 39000 12000 88000 82000 154000 85000 110000 84000 174000 180000 15000 151000 141000 115000 79000 110000 98000 73000 188000 177000 132000 156000 89000 113000 8000 141000 190000 123000 163000 28000 184000 178000 0 71000 85000 174000 71000 133000 67000 153000 95000 168000 25000 76000 29000 50000 198000 109000 93000 86000 80000 116000 49000 \ No newline at end of file diff --git a/lab19/lab19/lab19.vcxproj b/lab19/lab19/lab19.vcxproj index 9b36182..a129960 100644 --- a/lab19/lab19/lab19.vcxproj +++ b/lab19/lab19/lab19.vcxproj @@ -104,6 +104,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + Default Console @@ -132,7 +133,9 @@ + + diff --git a/lab19/lab19/lab19.vcxproj.filters b/lab19/lab19/lab19.vcxproj.filters index 0adab46..d3cb4df 100644 --- a/lab19/lab19/lab19.vcxproj.filters +++ b/lab19/lab19/lab19.vcxproj.filters @@ -32,5 +32,11 @@ Файлы ресурсов + + Файлы ресурсов + + + Файлы ресурсов + \ No newline at end of file diff --git a/lab19/lab19/main.c b/lab19/lab19/main.c index 2b0551c..d963a14 100644 --- a/lab19/lab19/main.c +++ b/lab19/lab19/main.c @@ -75,7 +75,7 @@ void save(int arr[], int len, char filename[]) { void saveRandomArray() { int len = 1000; - char filename[] = "in3.txt"; + char filename[] = "in4.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 - 20; + parr[i] = rand() % 200 * 1000; } save(parr, len, filename); @@ -142,6 +142,7 @@ void task3() { if (count == 0) { puts("no temp that is > 0 and < average, exiting task3()"); + free(arr); return; } @@ -166,6 +167,36 @@ void task3() { free(parr); } +void task4() { + int* pdata; + int len = load(&pdata, "in4.txt"); + + int max = pdata[0]; + for (int i = 0; i < len; i++) { + if (pdata[i] > max) max = pdata[i]; + } + + int* pout = (int*)malloc(sizeof(int) * len); + if (pout == NULL) { + puts("Out of memory"); + exit(EXIT_FAILURE); + } + + double high = (double)max * 0.667; + int count = 0; + for (int i = 0; i < len; i++) { + if (pdata[i] >= high) { + pout[count] = pdata[i]; + count++; + } + } + + save(pout, count, "out4.txt"); + + free(pdata); + free(pout); +} + int main() { //saveRandomArray(); @@ -182,20 +213,9 @@ int main() { //free(parr); //parr = NULL; - task3(); + //task3(); - /*int* pa; - pa = (int*)malloc(sizeof(int) * 140); - if (pa == NULL) { - printf_s("Not enough memory\n"); - exit(EXIT_FAILURE); - } - - pa[139] = 99; - printf_s("%d", pa[139]); - - free(pa); - pa = NULL;*/ + //task4(); return 0; } \ No newline at end of file diff --git a/lab19/lab19/out4.txt b/lab19/lab19/out4.txt new file mode 100644 index 0000000..50260fc --- /dev/null +++ b/lab19/lab19/out4.txt @@ -0,0 +1,2 @@ +332 +134000 169000 158000 162000 145000 161000 195000 142000 191000 153000 182000 171000 138000 133000 141000 147000 157000 141000 178000 190000 142000 170000 150000 193000 148000 154000 156000 166000 176000 144000 137000 138000 141000 177000 186000 145000 177000 173000 186000 161000 155000 167000 174000 150000 150000 141000 166000 191000 137000 153000 183000 145000 158000 188000 146000 168000 191000 162000 159000 137000 148000 195000 150000 174000 196000 148000 199000 134000 199000 138000 188000 135000 156000 198000 189000 195000 143000 187000 180000 196000 198000 189000 198000 157000 138000 179000 190000 158000 191000 156000 162000 142000 198000 157000 189000 189000 185000 182000 157000 169000 154000 189000 176000 168000 155000 149000 145000 153000 139000 196000 149000 149000 193000 195000 134000 186000 155000 185000 145000 156000 158000 182000 144000 196000 161000 135000 173000 154000 145000 186000 168000 187000 158000 191000 134000 172000 159000 177000 173000 163000 192000 185000 143000 172000 181000 193000 142000 187000 160000 174000 170000 160000 150000 140000 176000 171000 193000 152000 157000 170000 176000 158000 164000 165000 177000 162000 196000 137000 195000 171000 147000 153000 190000 188000 163000 140000 158000 178000 165000 160000 157000 193000 184000 140000 156000 150000 156000 157000 157000 137000 161000 185000 165000 159000 162000 184000 134000 172000 169000 163000 138000 142000 154000 141000 175000 134000 183000 198000 193000 134000 134000 156000 193000 176000 162000 148000 142000 152000 169000 189000 190000 145000 153000 140000 135000 159000 192000 181000 175000 197000 149000 156000 161000 141000 174000 192000 192000 159000 186000 170000 163000 171000 164000 142000 191000 150000 175000 139000 184000 171000 145000 146000 169000 185000 144000 140000 152000 170000 163000 169000 165000 143000 147000 143000 188000 142000 158000 154000 146000 149000 148000 136000 183000 185000 148000 159000 166000 144000 155000 155000 149000 184000 164000 142000 142000 196000 148000 173000 175000 165000 136000 141000 194000 136000 155000 186000 153000 148000 155000 161000 161000 148000 169000 171000 145000 181000 192000 189000 138000 161000 159000 137000 171000 155000 154000 174000 180000 151000 141000 188000 177000 156000 141000 190000 163000 184000 178000 174000 133000 153000 168000 198000 \ No newline at end of file