diff --git a/lab13/diagram (1).png b/lab13/diagram (1).png new file mode 100644 index 0000000..21788ee Binary files /dev/null and b/lab13/diagram (1).png differ diff --git a/lab13/lab13.sln b/lab13/lab13.sln new file mode 100644 index 0000000..a5fc60f --- /dev/null +++ b/lab13/lab13.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34616.47 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab13", "lab13\lab13.vcxproj", "{20A86935-1CE2-4A60-8957-361F97CB04AA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Debug|x64.ActiveCfg = Debug|x64 + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Debug|x64.Build.0 = Debug|x64 + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Debug|x86.ActiveCfg = Debug|Win32 + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Debug|x86.Build.0 = Debug|Win32 + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Release|x64.ActiveCfg = Release|x64 + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Release|x64.Build.0 = Release|x64 + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Release|x86.ActiveCfg = Release|Win32 + {20A86935-1CE2-4A60-8957-361F97CB04AA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DFB6070D-DF56-4483-A5CE-F17539C2A338} + EndGlobalSection +EndGlobal diff --git a/lab13/lab13/lab13.vcxproj b/lab13/lab13/lab13.vcxproj new file mode 100644 index 0000000..db7ce25 --- /dev/null +++ b/lab13/lab13/lab13.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {20a86935-1ce2-4a60-8957-361f97cb04aa} + lab13 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/lab13/lab13/lab13.vcxproj.filters b/lab13/lab13/lab13.vcxproj.filters new file mode 100644 index 0000000..669bc4e --- /dev/null +++ b/lab13/lab13/lab13.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/lab13/lab13/main.c b/lab13/lab13/main.c new file mode 100644 index 0000000..2c552cf --- /dev/null +++ b/lab13/lab13/main.c @@ -0,0 +1,187 @@ +#include +#include + +void arrayinput(int arr[], int len) { + printf(" %d \n", len); + for (int i = 0; i < len; i++) { + scanf_s(" %d", &arr[i]); + } +} + +void printarr(int arr[], int len) { + printf(" : ["); + for (int i = 0; i < len; i++) { + printf("%d, ", arr[i]); + } + printf("\b\b]\n"); +} + +void odds10x(int arr[], int len) { + for (int i = 0; i < len; i++) { + if (arr[i] % 2 != 0) arr[i] *= 10; + } +} + +void lasteven2x(int arr[], int len) { + for (int i = len - 1; i > 0; i--) { + if (arr[i] % 2 == 0) { + arr[i] *= 2; + break; + } + } +} + +int index(int num, int arr[], int len) { + for (int i = 0; i < len; i++) { + if (arr[i] == num) return i; + } + return -1; +} + +int arrmax(int arr[], int len) { + int max = arr[0]; + for (int i = 1; i < len; i++) { + if (arr[i] > max) max = arr[i]; + } + return max; +} + +int arrmin(int arr[], int len) { + int min = arr[0]; + for (int i = 1; i < len; i++) { + if (arr[i] < min) min = arr[i]; + } + return min; +} + +void switchmaxmin(int arr[], int len) { + int tmpmax = arrmax(arr, len); + int tmpmin = arrmin(arr, len); + int maxi = index(tmpmax, arr, len); + int mini = index(tmpmin, arr, len); + arr[maxi] = tmpmin; + arr[mini] = tmpmax; +} + +void evenleftmin(int arr[], int len) { + int id = index(arrmin(arr, len), arr, len); + int count = 0; + for (int i = 0; i < id; i++) { + if (arr[i] % 2 == 0) count++; + } + printf(" = %d\n", count); +} + +void negeven(int arr[], int len) { + for (int i = 0; i < len; i++) { + if (arr[i] % 2 == 0) arr[i] *= -1; + } +} + +void replace4(int arr[], int len) { + for (int i = 0; i < len; i++) { + if (arr[i] < 4) arr[i] = 4; + } +} + +void replacemax0(int arr[], int len) { + int maxi = index(arrmax(arr, len), arr, len); + for (int i = maxi; i < len; i++) { + if (arr[i] % 2 != 0) arr[i] = 0; + } +} + +void muleveneven(int arr[], int len) { + int even1 = 0; + int even2 = len - 1; + for (int i = 0; i < len; i++) { + if (arr[i] % 2 == 0) { + even1 = i + 1; + break; + } + } + for (int i = len - 1; i > 0; i--) { + if (arr[i] % 2 == 0) { + even2 = i; + break; + } + } + for (int i = even1; i < even2; i++) { + arr[i] *= 100; + } +} + +#define ARRNUM 10 + +int main() { + SetConsoleCP(1251); + SetConsoleOutputCP(1251); + + int arr[ARRNUM] = {5, 7, 12, 3, 4, 8, -1, 6, 1, 7}; + /*for (int i = 0; i < ARRNUM; i++) { + arr[i] = 0; + }*/ + + int n = -1; + do { + puts("\n"); + printarr(arr, ARRNUM); + puts(" "); + puts("1) "); + puts("2) 10"); + puts("3) 2"); + puts("4) "); + puts("6) "); + puts("7) -1"); + puts("8) 4 4"); + puts("9) , , 0"); + puts("11) 100 "); + puts(""); + puts("0) exit program"); + + while (scanf_s(" %d", &n) != 1) { + scanf_s("%*[^\n]"); + scanf_s("%*c"); + } + puts(""); + + switch (n) + { + case 1: + arrayinput(arr, ARRNUM); + break; + case 2: + odds10x(arr, ARRNUM); + break; + case 3: + lasteven2x(arr, ARRNUM); + break; + case 4: + evenleftmin(arr, ARRNUM); + break; + case 6: + switchmaxmin(arr, ARRNUM); + break; + case 7: + negeven(arr, ARRNUM); + break; + case 8: + replace4(arr, ARRNUM); + break; + case 9: + replacemax0(arr, ARRNUM); + break; + case 11: + muleveneven(arr, ARRNUM); + break; + case 0: + puts("goodbye :3"); + break; + default: + puts("error: wrong N"); + break; + } + + } while (n != 0); + return 0; +} \ No newline at end of file