From adfd0458db75c3c27c738f5dc51747618b5de4e2 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Thu, 17 Mar 2022 10:40:21 +0200 Subject: [PATCH 01/23] HW --- HomeWorks/HW1.cpp | 27 +++++++++++++++++++++++++++ HomeWorks/HW2.cpp | 0 2 files changed, 27 insertions(+) create mode 100644 HomeWorks/HW1.cpp create mode 100644 HomeWorks/HW2.cpp diff --git a/HomeWorks/HW1.cpp b/HomeWorks/HW1.cpp new file mode 100644 index 0000000..c3a4248 --- /dev/null +++ b/HomeWorks/HW1.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +int main01() +{ + int a, b, c; + cout << "a="; + cin >> a; + cout << "b="; + cin >> b; + /* //A + c=a; + a=b; + b=c;*/ + + /* //B + a+=b; + b=a-b; + a-=b;*/ + + /* //C + a*=b; + b=a/b; + a/=b;*/ + return 0; + +} \ No newline at end of file diff --git a/HomeWorks/HW2.cpp b/HomeWorks/HW2.cpp new file mode 100644 index 0000000..e69de29 From 862b32f9dc2668728fc5ea81d501c4bea9e31101 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Thu, 31 Mar 2022 08:59:12 +0300 Subject: [PATCH 02/23] Create HW3.cpp --- HomeWorks/HW3.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 HomeWorks/HW3.cpp diff --git a/HomeWorks/HW3.cpp b/HomeWorks/HW3.cpp new file mode 100644 index 0000000..7678b26 --- /dev/null +++ b/HomeWorks/HW3.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ +int n,sum=1,temp_sum=0,count1=2,count2=2; +cout << "n="; +cin >> n; +for(int i=2;i<=n;i++){ +temp_sum+=i; +if(count1>count2){ + sum*=temp_sum; + temp_sum=0; + count2=count1; +} +count1++; +} + +} \ No newline at end of file From c5f8dec38da21cfc41a9cdeaeb7557abe1b439f1 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Thu, 31 Mar 2022 10:07:07 +0300 Subject: [PATCH 03/23] Update HW3.cpp --- HomeWorks/HW3.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/HomeWorks/HW3.cpp b/HomeWorks/HW3.cpp index 7678b26..d126b85 100644 --- a/HomeWorks/HW3.cpp +++ b/HomeWorks/HW3.cpp @@ -3,17 +3,25 @@ using namespace std; int main() { -int n,sum=1,temp_sum=0,count1=2,count2=2; -cout << "n="; -cin >> n; -for(int i=2;i<=n;i++){ -temp_sum+=i; -if(count1>count2){ - sum*=temp_sum; - temp_sum=0; - count2=count1; -} -count1++; -} - + int n, sum = 1, temp_sum = 0, count = 0, l = 1; + cout << "n="; + cin >> n; + for (int i = 1; i <= n; i++) { + if (count == l) { + sum *= temp_sum; + cout << "tem_sum1 = " << temp_sum << " i=" << i << endl; + temp_sum = 0; + count = 0; + l++; + } + if (i == n) { + temp_sum += i; + sum *= temp_sum; + cout << "tem_sum2 = " << temp_sum << " i=" << i << endl; + } + count++; + temp_sum += i; + cout << "tem_sum4 = " << temp_sum << " i=" << i<< endl; + } + cout << "sum=" << sum; } \ No newline at end of file From 57c9e0efc7ace7a020b7cfd7b0b00c431349e5f3 Mon Sep 17 00:00:00 2001 From: Artur Chekalin <53403561+ArturChk@users.noreply.github.com> Date: Thu, 31 Mar 2022 10:08:36 +0300 Subject: [PATCH 04/23] Rename HW3.cpp to HW3_1.cpp --- HomeWorks/{HW3.cpp => HW3_1.cpp} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename HomeWorks/{HW3.cpp => HW3_1.cpp} (99%) diff --git a/HomeWorks/HW3.cpp b/HomeWorks/HW3_1.cpp similarity index 99% rename from HomeWorks/HW3.cpp rename to HomeWorks/HW3_1.cpp index d126b85..ca4f0dd 100644 --- a/HomeWorks/HW3.cpp +++ b/HomeWorks/HW3_1.cpp @@ -24,4 +24,4 @@ int main() cout << "tem_sum4 = " << temp_sum << " i=" << i<< endl; } cout << "sum=" << sum; -} \ No newline at end of file +} From fc2c1b1b399df96e46d1a7544f056eb3c4a06f06 Mon Sep 17 00:00:00 2001 From: Artur Chekalin <53403561+ArturChk@users.noreply.github.com> Date: Thu, 31 Mar 2022 10:20:42 +0300 Subject: [PATCH 05/23] Create HW3_2.cpp --- HomeWorks/HW3_2.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 HomeWorks/HW3_2.cpp diff --git a/HomeWorks/HW3_2.cpp b/HomeWorks/HW3_2.cpp new file mode 100644 index 0000000..fe5acf4 --- /dev/null +++ b/HomeWorks/HW3_2.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int fact(int n); + +int main() +{ + int n, sum = 0, factor_sum, count = 0, l = 1; + cout << "n="; + cin >> n; + for (int i = 1; i <= n; i++) { + factor_sum = fact(i); + sum += factor_sum; + } + cout << "sum=" << sum; + +} + +int fact(int n) { + int fact_sum = 1; + for (int i = 1; i <= n; i++) { + fact_sum *= i; + } + return fact_sum; + +} From 7c8f3880a1a843239e602aab8760ce4c887a8db6 Mon Sep 17 00:00:00 2001 From: Artur Chekalin <53403561+ArturChk@users.noreply.github.com> Date: Thu, 31 Mar 2022 10:45:04 +0300 Subject: [PATCH 06/23] Create HW3_3.cpp --- HomeWorks/HW3_3.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 HomeWorks/HW3_3.cpp diff --git a/HomeWorks/HW3_3.cpp b/HomeWorks/HW3_3.cpp new file mode 100644 index 0000000..35f86be --- /dev/null +++ b/HomeWorks/HW3_3.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int fact(int n,int l); + +int main() +{ + int n, sum = 0, temp_sum=1, count = 0, k = 1; + cout << "n="; + cin >> n; + for (int i = 1; i <= n; i++) { + cout << "sum= " << sum << endl; + sum += fact(i*i,i); + } + + cout << "sum=" << sum; + return 0; +} + +int fact(int n,int l) { + int fact_sum = 1; + for (int i = l; i <= n; i++) { + fact_sum *= i; + } + return fact_sum; +} From 599e33db3276fd54d71cb2193d22ec03325279bc Mon Sep 17 00:00:00 2001 From: Artur Chekalin <53403561+ArturChk@users.noreply.github.com> Date: Thu, 31 Mar 2022 10:47:54 +0300 Subject: [PATCH 07/23] Update HW3_3.cpp --- HomeWorks/HW3_3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HomeWorks/HW3_3.cpp b/HomeWorks/HW3_3.cpp index 35f86be..e27776e 100644 --- a/HomeWorks/HW3_3.cpp +++ b/HomeWorks/HW3_3.cpp @@ -5,7 +5,7 @@ int fact(int n,int l); int main() { - int n, sum = 0, temp_sum=1, count = 0, k = 1; + unsigned long long int n, sum = 0; cout << "n="; cin >> n; for (int i = 1; i <= n; i++) { From bc04ae21f9208582e4bc8ef4bf17072789da526f Mon Sep 17 00:00:00 2001 From: Artur Chekalin <53403561+ArturChk@users.noreply.github.com> Date: Thu, 31 Mar 2022 11:41:16 +0300 Subject: [PATCH 08/23] Create HW4.cpp --- HomeWorks/HW4.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 HomeWorks/HW4.cpp diff --git a/HomeWorks/HW4.cpp b/HomeWorks/HW4.cpp new file mode 100644 index 0000000..ce8148a --- /dev/null +++ b/HomeWorks/HW4.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; + +void create_matr(int n, int** matrix); +void print_matr(int n, int** matrix); +void sum_matr(int** matr1, int** matr2, int** matr3, int** matr_result, int n); +void fill_matr(int n, int** matrix); + +int main() +{ + int n; + cout << "n="; + cin >> n; + int** A = new int* [n]; + int** B = new int* [n]; + int** C = new int* [n]; + int** D = new int* [n]; + create_matr(n, A); cout << "Matrix A:" << endl; fill_matr(n, A); + create_matr(n, B); cout << "Matrix B:" << endl; fill_matr(n, B); + create_matr(n, C); cout << "Matrix C:" << endl; fill_matr(n, C); + create_matr(n, D); + sum_matr(A, B, C, D, n); + cout << "Matrix D:" << endl; + print_matr(n,D); + + return 0; +} + +void create_matr(int n, int** matrix) { + for (int i = 0; i < n; i++) + matrix[i] = new int[n]; +} + +void fill_matr(int n, int** matrix) { + unsigned int k; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + cin >> k; + matrix[i][j] = k; + } + cout << "\n\n"; +} + + +void print_matr(int n, int** matrix) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cout << matrix[i][j] << " "; + } + cout << endl; + } + cout << "\n\n\n"; +} + +void sum_matr(int** matr1, int** matr2,int** matr3,int**matr_result,int n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + matr_result[i][j] = matr1[i][j] + matr2[i][j] + matr3[i][j]; + } + } + +} From e18ca809f53dfdde987b8a5f63e78f181f866c99 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 16:39:56 +0300 Subject: [PATCH 09/23] update --- HomeWorks/HW2.cpp | 16 ++++++++++++++++ HomeWorks/HW3_1.cpp | 2 +- HomeWorks/HW3_2.cpp | 2 +- HomeWorks/HW3_3.cpp | 2 +- HomeWorks/HW4.cpp | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/HomeWorks/HW2.cpp b/HomeWorks/HW2.cpp index e69de29..5d9c39f 100644 --- a/HomeWorks/HW2.cpp +++ b/HomeWorks/HW2.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main(){ + int year; + cout << "year : "; + cin >> year; + if(year%4==0){ + if(year%100==0 && year%400==0) cout << "A leap year"; + else if(year%100!=0) cout << "A leap year"; + + } + else cout << "Is not a leap year"; + system("PAUSE"); + return 0; +} \ No newline at end of file diff --git a/HomeWorks/HW3_1.cpp b/HomeWorks/HW3_1.cpp index ca4f0dd..30a8cf3 100644 --- a/HomeWorks/HW3_1.cpp +++ b/HomeWorks/HW3_1.cpp @@ -1,7 +1,7 @@ #include using namespace std; -int main() +int main03() { int n, sum = 1, temp_sum = 0, count = 0, l = 1; cout << "n="; diff --git a/HomeWorks/HW3_2.cpp b/HomeWorks/HW3_2.cpp index fe5acf4..1d72557 100644 --- a/HomeWorks/HW3_2.cpp +++ b/HomeWorks/HW3_2.cpp @@ -3,7 +3,7 @@ using namespace std; int fact(int n); -int main() +int main04() { int n, sum = 0, factor_sum, count = 0, l = 1; cout << "n="; diff --git a/HomeWorks/HW3_3.cpp b/HomeWorks/HW3_3.cpp index e27776e..63d126d 100644 --- a/HomeWorks/HW3_3.cpp +++ b/HomeWorks/HW3_3.cpp @@ -3,7 +3,7 @@ using namespace std; int fact(int n,int l); -int main() +int main05() { unsigned long long int n, sum = 0; cout << "n="; diff --git a/HomeWorks/HW4.cpp b/HomeWorks/HW4.cpp index ce8148a..7f686ca 100644 --- a/HomeWorks/HW4.cpp +++ b/HomeWorks/HW4.cpp @@ -6,7 +6,7 @@ void print_matr(int n, int** matrix); void sum_matr(int** matr1, int** matr2, int** matr3, int** matr_result, int n); void fill_matr(int n, int** matrix); -int main() +int main05() { int n; cout << "n="; From b85101c966814da1c57e3eb7a12fc07e1728864e Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 16:43:30 +0300 Subject: [PATCH 10/23] ss --- .vscode/tasks.json | 48 ++++++++++++++++++++++++++++++++++++++++++++++ HomeWorks/HW2.cpp | 10 +++++----- 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..21045cb --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,48 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++.exe build active file", + "command": "C:\\MinGW\\bin\\g++.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": "build", + "detail": "Task generated by Debugger." + }, + { + "type": "cppbuild", + "label": "C/C++: cpp.exe build active file", + "command": "C:\\MinGW\\bin\\cpp.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/HomeWorks/HW2.cpp b/HomeWorks/HW2.cpp index 5d9c39f..53ab7a6 100644 --- a/HomeWorks/HW2.cpp +++ b/HomeWorks/HW2.cpp @@ -6,11 +6,11 @@ int main(){ cout << "year : "; cin >> year; if(year%4==0){ - if(year%100==0 && year%400==0) cout << "A leap year"; - else if(year%100!=0) cout << "A leap year"; - - } - else cout << "Is not a leap year"; + if(year%100==0 && year%400==0) cout << "A leap year\n"; + else if(year%100!=0) cout << "A leap year\n"; + else cout << "Is not a leap year\n"; +} + else cout << "Is not a leap year\n"; system("PAUSE"); return 0; } \ No newline at end of file From fcc193d267e1d14a26743bfb767eb1b037699fce Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 18:03:55 +0300 Subject: [PATCH 11/23] s --- .vscode/c_cpp_properties.json | 16 +++++++ .vscode/launch.json | 26 +++++++++++ .vscode/settings.json | 30 ++++++++++++ HomeWorks/HW2.cpp | 2 +- HomeWorks/HW5.cpp | 0 HomeWorks/HW6_1.cpp | 87 +++++++++++++++++++++++++++++++++++ 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 HomeWorks/HW5.cpp create mode 100644 HomeWorks/HW6_1.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..6d8e8c8 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x86", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/MinGW/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x86", + "compilerArgs": [] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1d9d03b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "cwd": "c:/pmp2021/HomeWorks", + "environment": [], + "program": "c:/pmp2021/HomeWorks/build/Debug/outDebug", + "internalConsoleOptions": "openOnSessionStart", + "MIMode": "gdb", + "miDebuggerPath": "C:/MinGW/bin/gdb.exe", + "externalConsole": false, + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5f0f8dd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,30 @@ +{ + "C_Cpp_Runner.cCompilerPath": "C:/MinGW/bin/gcc.exe", + "C_Cpp_Runner.cppCompilerPath": "C:/MinGW/bin/g++.exe", + "C_Cpp_Runner.debuggerPath": "C:/MinGW/bin/gdb.exe", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ] +} \ No newline at end of file diff --git a/HomeWorks/HW2.cpp b/HomeWorks/HW2.cpp index 53ab7a6..da8def4 100644 --- a/HomeWorks/HW2.cpp +++ b/HomeWorks/HW2.cpp @@ -1,7 +1,7 @@ #include using namespace std; -int main(){ +int main02(){ int year; cout << "year : "; cin >> year; diff --git a/HomeWorks/HW5.cpp b/HomeWorks/HW5.cpp new file mode 100644 index 0000000..e69de29 diff --git a/HomeWorks/HW6_1.cpp b/HomeWorks/HW6_1.cpp new file mode 100644 index 0000000..6b5dc71 --- /dev/null +++ b/HomeWorks/HW6_1.cpp @@ -0,0 +1,87 @@ +#include +using namespace std; + +void create_matr(int** matrix, int n); +void fill_matr(int** matrix, int n); +void diff_matr(int** matr1, int** matr2, int** matr3, int n); +void square_matr(int** matr1, int** matr2, int n); +void print_matr(int** matr, int n); +void delete_matr(int** matr, int n); + +int main() { + int n; + cout << "n="; + cin >> n; + int** A = new int* [n]; + int** B = new int* [n]; + int** C = new int* [n]; + int** D = new int* [n]; + create_matr(A, n); cout << "Matrix A:" << endl; fill_matr(A, n); + create_matr(B, n); cout << "Matrix B:" << endl; fill_matr(B, n); + create_matr(C, n); + create_matr(D, n); + diff_matr(A, B, C, n); + cout << "Matrix C:" << endl; + print_matr(C, n); + square_matr(C,D, n); + cout << "Matrix C^2:" << endl; + print_matr(D, n); + delete_matr(A, n); + delete_matr(B, n); + delete_matr(C, n); + delete_matr(D, n); + system("PAUSE"); + return 0; +} + +void delete_matr(int** matr, int n) { + for (int i = 0; i < n; i++) + delete[] matr[i]; + delete[] matr; +} + +void create_matr(int** matrix, int n) { + for (int i = 0; i < n; i++) + matrix[i] = new int[n]; +} + +void fill_matr(int** matrix, int n) { + unsigned int k; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + cin >> k; + matrix[i][j] = k; + } + cout << "\n\n"; +} + +void print_matr(int** matr, int n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) + cout << matr[i][j] << " "; + cout << endl; + } + cout << endl; +} + +void diff_matr(int** matr1, int** matr2, int** matr3, int n) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + matr3[i][j] = matr1[i][j] - matr2[i][j]; + } + } + +} + +void square_matr(int** matr1, int** matr2, int n) { + int sum; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + sum = 0; + for (int k = 0; k < n; k++) { + sum += matr1[i][k] * matr1[k][j]; + } + matr2[i][j] = sum; + } + } +} \ No newline at end of file From a7032c8f9285bb4d45cd85b3df6b53df4a750321 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 18:19:59 +0300 Subject: [PATCH 12/23] s --- .vscode/launch.json | 4 ++-- .vscode/settings.json | 5 ++++- HomeWorks/HW6_2.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 HomeWorks/HW6_2.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json index 1d9d03b..156a171 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,9 +7,9 @@ "request": "launch", "args": [], "stopAtEntry": false, - "cwd": "c:/pmp2021/HomeWorks", + "cwd": "c:/pmp2021", "environment": [], - "program": "c:/pmp2021/HomeWorks/build/Debug/outDebug", + "program": "c:/pmp2021/build/Release/outRelease", "internalConsoleOptions": "openOnSessionStart", "MIMode": "gdb", "miDebuggerPath": "C:/MinGW/bin/gdb.exe", diff --git a/.vscode/settings.json b/.vscode/settings.json index 5f0f8dd..ba99ebc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,5 +26,8 @@ "**/.*/**", "**/.vscode", "**/.vscode/**" - ] + ], + "files.associations": { + "iostream": "cpp" + } } \ No newline at end of file diff --git a/HomeWorks/HW6_2.cpp b/HomeWorks/HW6_2.cpp new file mode 100644 index 0000000..2386ae7 --- /dev/null +++ b/HomeWorks/HW6_2.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +void create_matr(int** matrix, int n); +void fill_matr(int** matrix, int n); +bool diagonal_matr(int** matrix, int n); + +int main() { + int n; + cout << "n="; + cin >> n; + int** A = new int* [n]; + create_matr(A, n); fill_matr(A, n); + if (diagonal_matr(A, n)) cout << "Yes" << endl; + else cout << "No" << endl; + system("PAUSE"); + return 0; +} + +bool diagonal_matr(int** matrix, int n) { + int count = 0, J = 0; + int abs_sum; + for (int i = 0; i < n; i++) { + abs_sum = 0; + for (int j = 0; j < n; j++) { + if (j != i) abs_sum += matrix[i][j]; + } + if (matrix[i][J] >= abs_sum) count++; + J++; + } + cout << "count = " << count << endl; + if (count == n) return true; + return false; +} + +void create_matr(int** matrix, int n) { + for (int i = 0; i < n; i++) + matrix[i] = new int[n]; +} + +void fill_matr(int** matrix, int n) { + unsigned int k; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + cin >> k; + matrix[i][j] = k; + } + cout << "\n\n"; +} \ No newline at end of file From f5be168527a2c4f0c1caa1fd6f39f416bb87730b Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 18:59:27 +0300 Subject: [PATCH 13/23] s --- .vscode/c_cpp_properties.json | 16 ---------- .vscode/launch.json | 26 ---------------- .vscode/settings.json | 33 --------------------- .vscode/tasks.json | 20 ------------- HomeWorks/HW7_1.cpp | 56 +++++++++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 95 deletions(-) delete mode 100644 .vscode/c_cpp_properties.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json create mode 100644 HomeWorks/HW7_1.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 6d8e8c8..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "configurations": [ - { - "name": "windows-gcc-x86", - "includePath": [ - "${workspaceFolder}/**" - ], - "compilerPath": "C:/MinGW/bin/gcc.exe", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "windows-gcc-x86", - "compilerArgs": [] - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 156a171..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "cwd": "c:/pmp2021", - "environment": [], - "program": "c:/pmp2021/build/Release/outRelease", - "internalConsoleOptions": "openOnSessionStart", - "MIMode": "gdb", - "miDebuggerPath": "C:/MinGW/bin/gdb.exe", - "externalConsole": false, - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ba99ebc..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "C_Cpp_Runner.cCompilerPath": "C:/MinGW/bin/gcc.exe", - "C_Cpp_Runner.cppCompilerPath": "C:/MinGW/bin/g++.exe", - "C_Cpp_Runner.debuggerPath": "C:/MinGW/bin/gdb.exe", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "", - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "files.associations": { - "iostream": "cpp" - } -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 21045cb..6a85229 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -17,26 +17,6 @@ "problemMatcher": [ "$gcc" ], - "group": "build", - "detail": "Task generated by Debugger." - }, - { - "type": "cppbuild", - "label": "C/C++: cpp.exe build active file", - "command": "C:\\MinGW\\bin\\cpp.exe", - "args": [ - "-fdiagnostics-color=always", - "-g", - "${file}", - "-o", - "${fileDirname}\\${fileBasenameNoExtension}.exe" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], "group": { "kind": "build", "isDefault": true diff --git a/HomeWorks/HW7_1.cpp b/HomeWorks/HW7_1.cpp new file mode 100644 index 0000000..a9a1967 --- /dev/null +++ b/HomeWorks/HW7_1.cpp @@ -0,0 +1,56 @@ +#include +using namespace std; + +void create_matr(int **matrix,int n); +void fill_matr(int **matrix,int n); +void t_matr(int **matrix1,int** matrix2,int n); +void print_matr(int** matr, int n); + +int main(){ + int n; + cout << "n="; + cin >> n; + int** A = new int* [n]; + int** AT = new int* [n]; + create_matr(A,n); fill_matr(A,n); + create_matr(AT,n); + t_matr(A,AT,n); + cout << "transported matrix:\n"; + print_matr(AT,n); + system("PAUSE"); + return 0; +} + +void t_matr(int **matrix1,int** matrix2,int n){ + for(int i=0;i> k; + matrix[i][j] = k; + } + cout << "\n\n"; +} From 4040ef96226c0f9fe4f375df83c77dd044fe3e31 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 19:17:05 +0300 Subject: [PATCH 14/23] s --- HomeWorks/HW7_2.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 HomeWorks/HW7_2.cpp diff --git a/HomeWorks/HW7_2.cpp b/HomeWorks/HW7_2.cpp new file mode 100644 index 0000000..fab3a74 --- /dev/null +++ b/HomeWorks/HW7_2.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; + +void create_matrix(int ** matrix,int n); +bool symmetrical_matrix(int **matrix,int n); + +int main(){ + int n; + cout << "n="; + cin >> n; + int** A = new int* [n]; + create_matrix(A,n); + if(symmetrical_matrix(A,n)) cout << "Yes, matrix is symmetrical about the diagonal \n"; + else cout << "No matrix is not symmetrical about the diagonal\n"; + system("PAUSE"); + return 0; +} + + +bool symmetrical_matrix(int **matrix,int n){ + for(int i=0;i> k; + matrix[i][j] = k; + } + cout << "\n\n"; +} \ No newline at end of file From 6f63ca90593b9209e80b5cbc2e978ed3c245b765 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 19:39:10 +0300 Subject: [PATCH 15/23] s --- HomeWorks/HW5.cpp | 0 HomeWorks/HW5_2.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) delete mode 100644 HomeWorks/HW5.cpp create mode 100644 HomeWorks/HW5_2.cpp diff --git a/HomeWorks/HW5.cpp b/HomeWorks/HW5.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/HomeWorks/HW5_2.cpp b/HomeWorks/HW5_2.cpp new file mode 100644 index 0000000..e40e224 --- /dev/null +++ b/HomeWorks/HW5_2.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int recursive_sum(int n); + +int main(){ + int n; + cout << "n="; + cin >> n; + cout << "sum= " << recursive_sum(n) << endl; + system("PAUSE"); + return 0; +} + +int recursive_sum(int n){ + if(n<=2) return n; + return recursive_sum(n-2)+n; + +} \ No newline at end of file From dc0fabc6ad5b9aac08960848b0b0d9bf336a772c Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 22:14:01 +0300 Subject: [PATCH 16/23] Create HW5_1_a.cpp --- HomeWorks/HW5_1_a.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 HomeWorks/HW5_1_a.cpp diff --git a/HomeWorks/HW5_1_a.cpp b/HomeWorks/HW5_1_a.cpp new file mode 100644 index 0000000..45d2ef7 --- /dev/null +++ b/HomeWorks/HW5_1_a.cpp @@ -0,0 +1,30 @@ +#include +#include +using namespace std; + +double rec_sin1(int n,int k); +double rec_sin2(int n,int k); + +int main() { + int n,k; + cout << "n="; + cin >> n; + k = n; + cout << "sin1 " << sin(1) << endl << "sin2 " << sin(sin(1)) + sin(2) << endl << "sin3 " << sin(sin(sin(1))) + sin(sin(2)) + sin(3) << endl; + cout << "sin4 " << sin(sin(sin(sin(1)))) + sin(sin(sin(2))) + sin(sin(3)) + sin(4)<< endl; + cout << "rec_sin = " < Date: Tue, 5 Apr 2022 22:14:55 +0300 Subject: [PATCH 17/23] ss --- HomeWorks/HW5_1_a.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/HomeWorks/HW5_1_a.cpp b/HomeWorks/HW5_1_a.cpp index 45d2ef7..9729a83 100644 --- a/HomeWorks/HW5_1_a.cpp +++ b/HomeWorks/HW5_1_a.cpp @@ -13,6 +13,7 @@ int main() { cout << "sin1 " << sin(1) << endl << "sin2 " << sin(sin(1)) + sin(2) << endl << "sin3 " << sin(sin(sin(1))) + sin(sin(2)) + sin(3) << endl; cout << "sin4 " << sin(sin(sin(sin(1)))) + sin(sin(sin(2))) + sin(sin(3)) + sin(4)<< endl; cout << "rec_sin = " < Date: Tue, 5 Apr 2022 22:18:57 +0300 Subject: [PATCH 18/23] s --- HomeWorks/HW5_1_a.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HomeWorks/HW5_1_a.cpp b/HomeWorks/HW5_1_a.cpp index 9729a83..892117b 100644 --- a/HomeWorks/HW5_1_a.cpp +++ b/HomeWorks/HW5_1_a.cpp @@ -11,7 +11,7 @@ int main() { cin >> n; k = n; cout << "sin1 " << sin(1) << endl << "sin2 " << sin(sin(1)) + sin(2) << endl << "sin3 " << sin(sin(sin(1))) + sin(sin(2)) + sin(3) << endl; - cout << "sin4 " << sin(sin(sin(sin(1)))) + sin(sin(sin(2))) + sin(sin(3)) + sin(4)<< endl; + cout << "sin4 " << sin(sin(sin(sin(1)))) + sin(sin(sin(2))) + sin(sin(3)) + sin(4)<< endl<< "sin5 "< Date: Tue, 5 Apr 2022 22:19:41 +0300 Subject: [PATCH 19/23] Rename HW5_1_a.cpp to HW5_1_b.cpp --- HomeWorks/{HW5_1_a.cpp => HW5_1_b.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename HomeWorks/{HW5_1_a.cpp => HW5_1_b.cpp} (100%) diff --git a/HomeWorks/HW5_1_a.cpp b/HomeWorks/HW5_1_b.cpp similarity index 100% rename from HomeWorks/HW5_1_a.cpp rename to HomeWorks/HW5_1_b.cpp From 638b74493fd760e505e68dd7f865e1e222b0da21 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 22:50:14 +0300 Subject: [PATCH 20/23] Update HW5_1_b.cpp --- HomeWorks/HW5_1_b.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HomeWorks/HW5_1_b.cpp b/HomeWorks/HW5_1_b.cpp index 892117b..8179708 100644 --- a/HomeWorks/HW5_1_b.cpp +++ b/HomeWorks/HW5_1_b.cpp @@ -28,4 +28,4 @@ double rec_sin1(int n,int k) { double rec_sin2(int n,int k) { if (n == 0) return 0; return rec_sin1(n, k) + rec_sin2(n - 1, k); -} +} \ No newline at end of file From bed6a55f4c00c405378aa77996ac316c7492eadd Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Tue, 5 Apr 2022 22:51:28 +0300 Subject: [PATCH 21/23] Create HW5_1_a.cpp --- HomeWorks/HW5_1_a.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 HomeWorks/HW5_1_a.cpp diff --git a/HomeWorks/HW5_1_a.cpp b/HomeWorks/HW5_1_a.cpp new file mode 100644 index 0000000..af779d2 --- /dev/null +++ b/HomeWorks/HW5_1_a.cpp @@ -0,0 +1,32 @@ +#include +#include +using namespace std; + +double rec_vkl(int n); + +int main() { + int n; + cout << "n="; + cin >> n; + cout << "sin1 " << sin(1) << endl << "sin2 " << sin(sin(1)) + sin(2) << endl << "sin3 " << sin(sin(sin(1))) + sin(sin(2)) + sin(3) << endl; + cout << "sin4 " << sin(sin(sin(sin(1)))) + sin(sin(sin(2))) + sin(sin(3)) + sin(4) <=1;j--) { + k = sin(k); + } + n--; + sum += k; + } + return sum; +} + From 5bb23c89bb74673b3f935bd0656d846d16effa8c Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Wed, 25 May 2022 12:42:33 +0300 Subject: [PATCH 22/23] Create HW14.cpp --- HomeWorks/HW14.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 HomeWorks/HW14.cpp diff --git a/HomeWorks/HW14.cpp b/HomeWorks/HW14.cpp new file mode 100644 index 0000000..c07a4e2 --- /dev/null +++ b/HomeWorks/HW14.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; + +class Queue { + int size; + int* queue; + +public: + Queue() { + size = 0; + queue = new int[100]; + } + void add(int data) { + queue[size] = data; + size++; + } + void remove() { + if (size == 0) { + cout << "Queue is empty" << endl; + return; + } + else { + for (int i = 0; i < size - 1; i++) { + queue[i] = queue[i + 1]; + } + size--; + } + } + void print() { + if (size == 0) { + cout << "Queue is empty" << endl; + return; + } + for (int i = 0; i < size; i++) { + cout << queue[i] << " <- "; + } + cout << endl; + } + Queue operator+(Queue& obj) { + Queue q3; + q3.size = this->size; + q3.queue = this->queue; + for (int i = 0; i < obj.size; i++) { + q3.add(obj.queue[i]); + } + return q3; + } +}; + +int main() { + Queue q1; + q1.add(42); q1.add(2); q1.add(8); q1.add(1); + Queue q2; + q2.add(3); q2.add(66); q2.add(128); q2.add(5); q2.add(16); q2.add(2222); + Queue q3 = q1 + q2; + q3.print(); + + return 0; +} \ No newline at end of file From 475deacffc4371ff51a063e4cb17af75ee4bd852 Mon Sep 17 00:00:00 2001 From: Artur Chekalin Date: Wed, 25 May 2022 13:13:29 +0300 Subject: [PATCH 23/23] Create HW13.cpp --- HomeWorks/HW13.cpp | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 HomeWorks/HW13.cpp diff --git a/HomeWorks/HW13.cpp b/HomeWorks/HW13.cpp new file mode 100644 index 0000000..498b3dc --- /dev/null +++ b/HomeWorks/HW13.cpp @@ -0,0 +1,137 @@ +#include +using namespace std; + +#define Element int + +struct ArrayStack +{ + Element* data; + int n; + int sp; +}; + +void arrStackCreate(ArrayStack*& stack, int n) +{ + stack = new ArrayStack(); + stack->data = new int[n]; + stack->n = n; + stack->sp = -1; + for (int i = 0; i < n; i++) + { + stack->data[i] = 0; + } +} + + +bool arrStackPush(ArrayStack* stack, Element element) +{ + bool result = (stack->sp < stack->n - 1); + if (result) + { + stack->sp++; + stack->data[stack->sp] = element; + } + return result; +} + + +bool arrStackPushs(ArrayStack* stack, Element* element, int n) +{ + bool result = true; + for (int i = 0; result && (i < n); i++) + { + result = arrStackPush(stack, element[i]); + } + if (!result) + { + cout << "ERROR: Stack Overflow" << endl; + } + return result; +} + +bool arrStackIsEmpty(ArrayStack* stack) +{ + return (stack->sp < 0); +} + +Element* arrStackPop(ArrayStack* stack, bool* result = NULL) +{ + Element* element = NULL; + bool status = arrStackIsEmpty(stack); + if (result == NULL) + { + result = &status; + } + else + { + *result = status; + } + if (!*result) + { + element = &stack->data[stack->sp]; + stack->sp--; + } + return element; +} + +void arrStackDelete(ArrayStack* stack) +{ + delete[] stack->data; + delete stack; +} + +void arrStackPrint(ArrayStack* stack, const char* Message) +{ + cout << "\nStack: " << Message << endl; + cout << "n = " << stack->n << endl; + cout << "sp = " << stack->sp << endl; + for (int i = 0; i <= stack->sp; i++) + { + cout << "element[" << i << "] = " << stack->data[i] << endl; + } +} +void arrPrintStack(ArrayStack* stack) { + int size = stack->n; + if (size == 0) { + cout << "Stack is empty" << endl; + return; + } + for (int i = 0; i < size; i++) { + cout << stack->data[i] << " "; + } + cout << endl; +} + +int main() +{ + int n1 = 12, n2 = 10, n3 = n1 + n2; + ArrayStack* stack1 = NULL; + ArrayStack* stack2 = NULL; + ArrayStack* stack3 = NULL; + Element* elemArray1 = new Element[n1]{ 2, 2, 3, 4, 3, 6, 7, 1, 9, 10,66,101 }; + Element* elemArray2 = new Element[n2]{ 7, 2, 4, 4, 5, 6, 7, 8, 9, 10 }; + arrStackCreate(stack1, n1); + arrStackCreate(stack2, n2); + arrStackCreate(stack3, n3); + arrStackPushs(stack1, elemArray1, n1); + arrStackPushs(stack2, elemArray2, n2); + arrStackPushs(stack3, elemArray1, n1); + arrStackPushs(stack3, elemArray2, n2); + //arrStackPrint(stack1, "After Add Array of Elements"); + cout << "stack 1 = "; + arrPrintStack(stack1); + cout << "stack 2 = "; + arrPrintStack(stack2); + cout << "stack 3 = "; + while (!arrStackIsEmpty(stack3)) + { + cout << *arrStackPop(stack3)<< " "; + } + cout << endl; + arrStackDelete(stack1); + arrStackDelete(stack2); + arrStackDelete(stack3); + // + cout << "\ndone" << endl; + return 0; +} \ No newline at end of file