From 60a7ef49992dfb77c2ee3b8d02c56be582e72100 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 16:13:58 +0300 Subject: solved ex 8 and 9 from sem. 3 --- Sem. 03/exercise 8 - dollar pyramid.cpp | 17 +++++++++++++++++ Sem. 03/exercise 9 - rightmost pyramid.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Sem. 03/exercise 8 - dollar pyramid.cpp create mode 100644 Sem. 03/exercise 9 - rightmost pyramid.cpp diff --git a/Sem. 03/exercise 8 - dollar pyramid.cpp b/Sem. 03/exercise 8 - dollar pyramid.cpp new file mode 100644 index 0000000..e32c5ba --- /dev/null +++ b/Sem. 03/exercise 8 - dollar pyramid.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +void printPyramid(int n) { + for(int i = 1; i <= n; i++) { + for(int j = 1; j <= i; j++) + cout << "$" << " "; // print as many dollars as the number of the current row + cout << endl; + } +} + +int main() { + int n; + cin >> n; + printPyramid(n); + return 0; +} \ No newline at end of file diff --git a/Sem. 03/exercise 9 - rightmost pyramid.cpp b/Sem. 03/exercise 9 - rightmost pyramid.cpp new file mode 100644 index 0000000..f966fa2 --- /dev/null +++ b/Sem. 03/exercise 9 - rightmost pyramid.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +void printRightmostPyramid(int n) { + // print the first part of the pyramid (the one going from 1 to n(n-1)...21) + for(int i = 1; i <= n; i++) { + for(int k = n - i; k >= 0; k--) cout << " "; // print the spaces + for(int j = i; j >= 1; j--) cout << j; // print numbers j(j - 1)...21 + cout << endl; + } + // print the first part of the pyramid (the one going from (n-1)...21 to 1 + for(int i = n - 1; i >= 1; i--) { + for(int k = n - i; k >= 0; k--) cout << " "; + for(int j = i; j >= 1; j--) cout << j; + cout << endl; + } +} + +int main() { + int n; + cin >> n; + printRightmostPyramid(n); + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 616692d1e3605bbc77754c90434b82eb6b41c1d8 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 16:45:14 +0300 Subject: solved ex 8 and 9 from sem. 3 --- Sem. 03/exercise 8 - dollar pyramid.cpp | 17 ---------- Sem. 03/exercise 9 - rightmost pyramid.cpp | 24 --------------- Sem. 03/solutions/exercise 8 - dollar pyramid.cpp | 19 ++++++++++++ .../solutions/exercise 9 - rightmost pyramid.cpp | 36 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 41 deletions(-) delete mode 100644 Sem. 03/exercise 8 - dollar pyramid.cpp delete mode 100644 Sem. 03/exercise 9 - rightmost pyramid.cpp create mode 100644 Sem. 03/solutions/exercise 8 - dollar pyramid.cpp create mode 100644 Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp diff --git a/Sem. 03/exercise 8 - dollar pyramid.cpp b/Sem. 03/exercise 8 - dollar pyramid.cpp deleted file mode 100644 index e32c5ba..0000000 --- a/Sem. 03/exercise 8 - dollar pyramid.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -using namespace std; - -void printPyramid(int n) { - for(int i = 1; i <= n; i++) { - for(int j = 1; j <= i; j++) - cout << "$" << " "; // print as many dollars as the number of the current row - cout << endl; - } -} - -int main() { - int n; - cin >> n; - printPyramid(n); - return 0; -} \ No newline at end of file diff --git a/Sem. 03/exercise 9 - rightmost pyramid.cpp b/Sem. 03/exercise 9 - rightmost pyramid.cpp deleted file mode 100644 index f966fa2..0000000 --- a/Sem. 03/exercise 9 - rightmost pyramid.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -using namespace std; - -void printRightmostPyramid(int n) { - // print the first part of the pyramid (the one going from 1 to n(n-1)...21) - for(int i = 1; i <= n; i++) { - for(int k = n - i; k >= 0; k--) cout << " "; // print the spaces - for(int j = i; j >= 1; j--) cout << j; // print numbers j(j - 1)...21 - cout << endl; - } - // print the first part of the pyramid (the one going from (n-1)...21 to 1 - for(int i = n - 1; i >= 1; i--) { - for(int k = n - i; k >= 0; k--) cout << " "; - for(int j = i; j >= 1; j--) cout << j; - cout << endl; - } -} - -int main() { - int n; - cin >> n; - printRightmostPyramid(n); - return 0; -} \ No newline at end of file diff --git a/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp new file mode 100644 index 0000000..65f6106 --- /dev/null +++ b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + + int n; + cin >> n; + + for(int i = 1; i <= n; i++) + { + for(int j = 1; j <= i; j++) + cout << "$" << " "; // print as many dollars as the number of the current row + + cout << endl; + } + + return 0; +} \ No newline at end of file diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp new file mode 100644 index 0000000..80408ac --- /dev/null +++ b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +int main() +{ + + int n; + cin >> n; + + // print the first part of the pyramid (the one going from 1 to n(n-1)...21) + + for(int i = 1; i <= n; i++) + { + for(int k = n - i; k >= 0; k--) + cout << " "; // print the spaces + + for(int j = i; j >= 1; j--) + cout << j; // print numbers j(j - 1)...21 + + cout << endl; + } + // print the first part of the pyramid (the one going from (n-1)...21 to 1 + + for(int i = n - 1; i >= 1; i--) + { + for(int k = n - i; k >= 0; k--) + cout << " "; + + for(int j = i; j >= 1; j--) + cout << j; + + cout << endl; + } + + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 7b293489a228d03fb295f5f9e12e6f8da5854cc1 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 09:46:46 -0400 Subject: Update README.md --- Sem. 03/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Sem. 03/README.md b/Sem. 03/README.md index 6fcb143..659c710 100644 --- a/Sem. 03/README.md +++ b/Sem. 03/README.md @@ -112,6 +112,7 @@ do *Вход: 0 0 -1 5 -6 Изход: 2 3* +**!** Задачите надолу са за рисуване на конзолата. Във файла *drawing_examples.txt* има изходите като текст. **Задача 8:** Да се напише програма, която приема цяло положително число n и отпечатва следната пирамида от доларчета -- cgit v1.3.1-23-gd82d From 06934b13b40ed298a23ae4776b35267e43b87ca4 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 09:47:50 -0400 Subject: Update README.md --- Sem. 03/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 03/README.md b/Sem. 03/README.md index 659c710..427d736 100644 --- a/Sem. 03/README.md +++ b/Sem. 03/README.md @@ -112,7 +112,7 @@ do *Вход: 0 0 -1 5 -6 Изход: 2 3* -**!** Задачите надолу са за рисуване на конзолата. Във файла *drawing_examples.txt* има изходите като текст. +**!!** Задачите надолу са за рисуване на конзолата. Във файла *drawing_examples.txt* има изходите като текст.**!!** **Задача 8:** Да се напише програма, която приема цяло положително число n и отпечатва следната пирамида от доларчета -- cgit v1.3.1-23-gd82d From 37407ad35d0c5e19a69d4154d54be2f14450474b Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 09:48:56 -0400 Subject: Update drawing_examples.txt --- Sem. 03/drawing_examples.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 03/drawing_examples.txt b/Sem. 03/drawing_examples.txt index 5179a0f..d8fad73 100644 --- a/Sem. 03/drawing_examples.txt +++ b/Sem. 03/drawing_examples.txt @@ -63,7 +63,7 @@ $ $ $ $ задача 11: -вход:9 +вход:3 1 2 3 6 5 4 7 8 9 -- cgit v1.3.1-23-gd82d From 9d1770ff8d52a99a68c414a5030366a2aec3c3a1 Mon Sep 17 00:00:00 2001 From: Стоян Златев <47269030+Tony5768@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:02:43 +0300 Subject: Create example 10 - matrix --- Sem. 03/example 10 - matrix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Sem. 03/example 10 - matrix diff --git a/Sem. 03/example 10 - matrix b/Sem. 03/example 10 - matrix new file mode 100644 index 0000000..dae43ab --- /dev/null +++ b/Sem. 03/example 10 - matrix @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + for (int j = 0; j < count; j++) + { + if (j % 2 == 0) + { + cout << i + (count * j) << " "; + } + else + { + cout << (j + 1) * count - (i - 1) << " "; + } + } + cout << endl; + } +} -- cgit v1.3.1-23-gd82d From 2f718a73d9226759f98d7d631f0d43ba180c5919 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:04:06 +0300 Subject: fixed styling and removed functions --- Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp index 80408ac..e95fa25 100644 --- a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp +++ b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp @@ -19,7 +19,7 @@ int main() cout << endl; } - // print the first part of the pyramid (the one going from (n-1)...21 to 1 + // print the second part of the pyramid (the one going from (n-1)...21 to 1 for(int i = n - 1; i >= 1; i--) { -- cgit v1.3.1-23-gd82d From 0901d0e587a4fd820d54dac9dca9477dff3b8670 Mon Sep 17 00:00:00 2001 From: Kristian Todorov <63777932+kristian3551@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:07:57 +0300 Subject: fixed styling and spacing of ex 9 --- Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp index e95fa25..d1b339a 100644 --- a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp +++ b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp @@ -11,7 +11,7 @@ int main() for(int i = 1; i <= n; i++) { - for(int k = n - i; k >= 0; k--) + for(int k = n - i - 1; k >= 0; k--) cout << " "; // print the spaces for(int j = i; j >= 1; j--) @@ -23,7 +23,7 @@ int main() for(int i = n - 1; i >= 1; i--) { - for(int k = n - i; k >= 0; k--) + for(int k = n - i - 1; k >= 0; k--) cout << " "; for(int j = i; j >= 1; j--) -- cgit v1.3.1-23-gd82d From 10ddc99b7eb7501b4da3e60d2bf3be0c5c2689a8 Mon Sep 17 00:00:00 2001 From: TihomirGalov Date: Thu, 28 Oct 2021 17:14:25 +0300 Subject: Fixed wrong output on task 2 28 and 21 have only two common dividers which are 7 and 1 in the second case there are missed dividers --- Sem. 03/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sem. 03/README.md b/Sem. 03/README.md index 427d736..af93bf2 100644 --- a/Sem. 03/README.md +++ b/Sem. 03/README.md @@ -67,9 +67,9 @@ do **Задача 2:** Да се напише програма, която приема 2 числа. Да се отпечатат всички общи делители сортиран наобратно. -*Вход: 28 21, Изход: 7 3 1* +*Вход: 28 21, Изход: 7 1* -*Вход: 60 30 Изход: 30 15 10 5 3 1* +*Вход: 60 30 Изход: 30 15 10 6 5 3 2 1* *Вход: 5 4 3 0 Изход: 12* -- cgit v1.3.1-23-gd82d From a94b6226e75e809d35bafa7a30bdbf988ed3a052 Mon Sep 17 00:00:00 2001 From: Стоян Златев <47269030+Tony5768@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:18:22 +0300 Subject: Create example 11 - reverse numbers by row --- Sem. 03/example 11 - reverse numbers by row | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Sem. 03/example 11 - reverse numbers by row diff --git a/Sem. 03/example 11 - reverse numbers by row b/Sem. 03/example 11 - reverse numbers by row new file mode 100644 index 0000000..66a90a9 --- /dev/null +++ b/Sem. 03/example 11 - reverse numbers by row @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + if (i % 2 != 0) + { + for (int j = 1 + ((i - 1) * count); j <= i * count; j++) + { + cout << j << " "; + } + } + else + { + for (int j = i * count; j > (i - 1) * count; j--) + { + cout << j << " "; + } + } + cout << endl; + } +} -- cgit v1.3.1-23-gd82d From 00f15aa8d69a53c3ffa55661283aa06a6d6bd30f Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Thu, 28 Oct 2021 17:33:12 +0300 Subject: Update sem.03 --- pract_SI/Pract. 03-04/Solutions/task1.cpp | 19 ----- pract_SI/Pract. 03-04/Solutions/task2.cpp | 17 ---- pract_SI/Pract. 03-04/Solutions/task3.cpp | 22 ----- pract_SI/Pract. 03-04/Solutions/task4.cpp | 21 ----- pract_SI/Pract. 03-04/Solutions/task5.cpp | 41 ---------- pract_SI/Pract. 03-04/Solutions/task6.cpp | 18 ---- pract_SI/Pract. 03-04/Solutions/task7.cpp | 30 ------- pract_SI/Pract. 03-04/Solutions/task8.cpp | 41 ---------- pract_SI/Pract. 03-04/Solutions/task9.cpp | 59 -------------- pract_SI/Pract. 03-04/Startup_tasks.txt | 7 -- pract_SI/Pract. 03-04/Tasks3.txt | 131 ------------------------------ pract_SI/Pract. 03/Solutions/task1.cpp | 19 +++++ pract_SI/Pract. 03/Solutions/task2.cpp | 17 ++++ pract_SI/Pract. 03/Solutions/task3.cpp | 22 +++++ pract_SI/Pract. 03/Solutions/task4.cpp | 21 +++++ pract_SI/Pract. 03/Solutions/task5.cpp | 41 ++++++++++ pract_SI/Pract. 03/Solutions/task6.cpp | 18 ++++ pract_SI/Pract. 03/Solutions/task7.cpp | 30 +++++++ pract_SI/Pract. 03/Solutions/task8.cpp | 41 ++++++++++ pract_SI/Pract. 03/Solutions/task9.cpp | 59 ++++++++++++++ pract_SI/Pract. 03/Startup_tasks.txt | 7 ++ pract_SI/Pract. 03/Tasks3.txt | 131 ++++++++++++++++++++++++++++++ 22 files changed, 406 insertions(+), 406 deletions(-) delete mode 100644 pract_SI/Pract. 03-04/Solutions/task1.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task2.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task3.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task4.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task5.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task6.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task7.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task8.cpp delete mode 100644 pract_SI/Pract. 03-04/Solutions/task9.cpp delete mode 100644 pract_SI/Pract. 03-04/Startup_tasks.txt delete mode 100644 pract_SI/Pract. 03-04/Tasks3.txt create mode 100644 pract_SI/Pract. 03/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task2.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task3.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task6.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task7.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task8.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task9.cpp create mode 100644 pract_SI/Pract. 03/Startup_tasks.txt create mode 100644 pract_SI/Pract. 03/Tasks3.txt diff --git a/pract_SI/Pract. 03-04/Solutions/task1.cpp b/pract_SI/Pract. 03-04/Solutions/task1.cpp deleted file mode 100644 index ae955a8..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task1.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "pch.h" -#include - -using namespace std; - -int main() -{ - unsigned long long number; - cin >> number; - - for (int i = 1; i <= number; i++) - { - for (int j = 1; j <= i; j++) - cout << j; - cout << endl; - } - - return 0; -} diff --git a/pract_SI/Pract. 03-04/Solutions/task2.cpp b/pract_SI/Pract. 03-04/Solutions/task2.cpp deleted file mode 100644 index b3e970d..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task2.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -using namespace std; - -int main() -{ - unsigned long long number; - cin >> number; - - for (unsigned long long x = 1, y = number; x < number; x++) - { - cout << "x = " << x << " " - << "y = " << --y << endl; - } - - return 0; -} diff --git a/pract_SI/Pract. 03-04/Solutions/task3.cpp b/pract_SI/Pract. 03-04/Solutions/task3.cpp deleted file mode 100644 index a6a6362..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task3.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned long long oldNumber, newNumber; - - cout << "Enter a positive number: "; - cin >> oldNumber; - - oldNumber *= oldNumber; - newNumber = 0; - - while (oldNumber != 0) - { - newNumber = newNumber * 10 + oldNumber % 10; - oldNumber /= 10; - } - - cout << newNumber << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03-04/Solutions/task4.cpp b/pract_SI/Pract. 03-04/Solutions/task4.cpp deleted file mode 100644 index 622b8a1..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task4.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned int m, n; - cout << "Number of rows: "; - cin >> m; - cout << "Number of columns: "; - cin >> n; - - for (unsigned int i = 1; i <= m * n; i++) - { - cout << i << " "; - if (i % n == 0) - { - cout << endl; - } - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03-04/Solutions/task5.cpp b/pract_SI/Pract. 03-04/Solutions/task5.cpp deleted file mode 100644 index d6ac57c..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task5.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned short number, guess; - unsigned int counter = 0; - - cout << "Enter a number between 0 and 100: "; - cin >> number; - if (number < 0 || number > 100) - { - cout << "Invalid input!\n"; - return 1; - } - - do - { - ++counter; - - cout << "Guess " << counter << ": "; - cin >> guess; - if (guess < 0 || guess > 100) - { - cout << "Invalid input!\n"; - return 2; - } - - if (guess < number) - { - cout << "The number you are looking for is greater than your guess!\n"; - } - else if (guess > number) - { - cout << "The number you are looking for is less than your guess!\n"; - } - } while (guess != number); - - cout << "You found the number in " << counter << " attempt(s)!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03-04/Solutions/task6.cpp b/pract_SI/Pract. 03-04/Solutions/task6.cpp deleted file mode 100644 index 8d0beac..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task6.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned int number = 0, input = 1; - - while(input != 0) - { - cout << "Enter a positive number: "; - cin >> input; - - number ^= input; - } - - cout << "The single number is " << number << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03-04/Solutions/task7.cpp b/pract_SI/Pract. 03-04/Solutions/task7.cpp deleted file mode 100644 index aa9194b..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task7.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#define LIMIT 5 -#define SEPARATOR " " - -using namespace std; - -//const short LIMIT = 5; -//const char SEPARATOR = ' '; - - -int main() -{ - unsigned long long N; - cin >> N; - - if (N < LIMIT) - return -1; - - for (int c = 1; c <= N; c++) { - for (int b = 1; b < c; b++) { - for (int a = 1; a < b; a++) { - if ((a * a) + (b * b) == (c * c)) { - cout << a << SEPARATOR << b << SEPARATOR << c << endl; - } - } - } - } - - return 0; -} diff --git a/pract_SI/Pract. 03-04/Solutions/task8.cpp b/pract_SI/Pract. 03-04/Solutions/task8.cpp deleted file mode 100644 index 3f32ebf..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task8.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; - -const short LOWERLIMIT = 2; -const short UPPERLIMIT = 9; -const char SEPARATOR = ' '; - -int main() -{ - short N; - char S; - cin >> N >> S; - - if (N < LOWERLIMIT || N > UPPERLIMIT) - return -1; //end program - - for (int i = 1; i <= N; i++) - { - for (int j = N - i; j > 0; j--) - cout << SEPARATOR; - - for (int k = 1; k < 2 * i; k++) - cout << S; - - cout << endl; - } - - for (int i = 1; i < N; i++) - { - for (int j = 1; j <= i; j++) - cout << SEPARATOR; - - for (int k = 1; k < 2 * (N - i); k++) - cout << S; - - cout << endl; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03-04/Solutions/task9.cpp b/pract_SI/Pract. 03-04/Solutions/task9.cpp deleted file mode 100644 index 9f1f054..0000000 --- a/pract_SI/Pract. 03-04/Solutions/task9.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -int main() { - - // по-нататък ще учим как се вкарват сложни данни, затова сега ще ги hardcode-нем в main-а - - int hoursOnesStart = 2, minutesTensStart = 5, secondsOnesStart = 6; - int hoursOnesFinal = 1, minutesTensFinal = 0, secondsOnesFinal = 2; - int hoursDelta = 10, minutesDelta = 19, secondsDelta = 26; - - for (size_t hoursTensStart = 0; hoursTensStart <= 1; ++hoursTensStart) - { - for (size_t minutesOnesStart = 0; minutesOnesStart <= 9; ++minutesOnesStart) - { - for (size_t secondsTensStart = 0; secondsTensStart <= 5; secondsTensStart++) - { - int hoursTemp = hoursTensStart * 10 + hoursOnesStart; - int minutesTemp = minutesTensStart * 10 + minutesOnesStart; - int secondsTemp = secondsTensStart * 10 + secondsOnesStart; - - secondsTemp += secondsDelta; - if (secondsTemp >= 60) { - minutesTemp += secondsTemp / 60; - secondsTemp %= 60; - } - - minutesTemp += minutesDelta; - if (minutesTemp >= 60) { - hoursTemp += minutesTemp / 60; - minutesTemp %= 60; - } - - hoursTemp += hoursDelta; - if (hoursTemp > 12) { - hoursTemp %= 12; - } - - bool hoursOnesMatch = hoursTemp % 10 == hoursOnesFinal, - minutesTensMatch = minutesTemp / 10 == minutesTensFinal, - secondsOnesMatch = secondsTemp % 10 == secondsOnesFinal; - - if (hoursOnesMatch && minutesTensMatch && secondsOnesMatch) { - int hoursTensFinal = hoursTemp / 10, - minutesOnesFinal = minutesTemp % 10, - secondsTensFinal = secondsTemp / 10; - - std::cout << hoursTensStart << hoursOnesStart << ':' - << minutesTensStart << minutesOnesStart << ':' - << secondsTensStart << secondsOnesStart << ' ' - << hoursTensFinal << hoursOnesFinal << ':' - << minutesTensFinal << minutesOnesFinal << ':' - << secondsTensFinal << secondsOnesFinal << '\n'; - } - } - } - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03-04/Startup_tasks.txt b/pract_SI/Pract. 03-04/Startup_tasks.txt deleted file mode 100644 index 8ee6d58..0000000 --- a/pract_SI/Pract. 03-04/Startup_tasks.txt +++ /dev/null @@ -1,7 +0,0 @@ -1.Напишете програма , която приема като вход N лева.Да се отпечата как бихме разпределили сумата на банкноти, -така че да имаме минимален брой банкноти. (Да не се използват условни оператори и цикли) -Пояснение: Нека да приемем, че имаме банкноти с 1лв и 2лв. - -2.Напишете програма, която приема като вход цяло положително число V, което ще отговаря на скорост. -Програмата да отпечатва колко е глобата от КАТ, а ако няма глоба следното съобщение "No speedticket". -(https://stamatovandpartners.com/elektronen-fish-za-previshena-skorost/) \ No newline at end of file diff --git a/pract_SI/Pract. 03-04/Tasks3.txt b/pract_SI/Pract. 03-04/Tasks3.txt deleted file mode 100644 index 64c5c4c..0000000 --- a/pract_SI/Pract. 03-04/Tasks3.txt +++ /dev/null @@ -1,131 +0,0 @@ -#Никола Светославов - task3 - -## Задачи - -1.Да се напише програма, която приема естествено число n и изписва стълба от 1 до n - -Пример -Вход: -5 -Изход: -1 -12 -123 -1234 -12345 - -2.Да се състави програма, която по въведено естествено число n да изведе всички естествени решения на уравнението x + y = n. - -Пример -Вход: -4 -Изход: -x = 1 y = 3 -x = 2 y = 2 -x = 3 y = 1 - - -3.Напишете програма, която по въведено цяло положително число, извежда квадратът на това число, но в обратен ред, като водещите нули се игнорират. - -Пример -Вход: -10 -Изход: -1 - -Вход: -25 -Изход: -526 - -4.Напишете програма, която приема от потребителя две цели положителни числа - *m* и *n*. - Програмата да отпечата числатаот 1 до m*n, като на всеки ред има по *n* числа (тоест ще отпечатате *m* реда). - Печатайте числата по редове: - -Пример -Вход: -2 3 -Изход: -1 2 3 -4 5 6 - -5.Напишете проста игра, в която първо се въвежда цяло число в интервала [0;100] и в последствие се въвеждат цели числа - (предположения), като за всяко се казва дали е по - малко или по - голямо от първоначално ваведеното. - Tова продължава до въвеждане на число, равно на първоначалното. Програмата да отпечата и броят направени предположения. - -6.Напишете програма, която иска от потребителя поредица от цели числа по - големи от 0. - Въвеждането приключва с въвеждане на 0. Гарантирано е, че всяко от числата е въведено **точно два пъти** освен едно, - което е въведено **точно веднъж**. Програмата да изведе кое е това число. - -7.Да се състави програма, която по въведено естествено число N намира и отпечатва всички тройки естествени числа a, b и c, - не по-големи от N, които могат да бъдат страни на правоъгълен триъгълник. - -Пример -Вход: -11 -Изход -3 4 5 -6 8 10 - -8.Напишете програма, която иска от потребителя вход цифра N[2;9] и символ S.Програмата да извежда фигура съставена от символа във вид на ромб, както е показано на примерите. - -Пример -Вход: -5 * -Изход - * - *** - ***** - ******* -********* - ******* - ***** - *** - * - -*Бонус* -Задача ЕЛЕКТРОНЕН ЧАСОВНИК -В големия нов МОЛ в града на програмистите се повредили част от цифрите на електронния часовник. -Повредени били първата цифра от числото, което показва часовете, втората цифра на числото, което показва минутите и първата цифра на числото, което показва секундите. -Вместо тях на екрана се появявал знака *. -Когато Коко и приятелите му ходели на кино, те не успявали да преценят точно колко е часа. -Все пак, момчетата си създали система за изчисление, която приблизително точно им показвало времето. -Те успявали да предвидят колко е показвал часовника в началото и края на филма, в случай че знаят точно колко време е минало. -Срещу името на всеки филм на входа на киното е дадено неговото времетраене в часове, минути и секунди. -Пресмятанията доста затрудняват момчетата и затова на тях ще им е по-удобно това да се прави с компютърна програма. -Те не разбират много от програмиране и затова вие трябва да напишете програма clock, която помага на Коко и приятелите му. - -Вход: -На първия ред на стандартния вход е записана последователност от цифри и знака *, която показва какво се вижда на екрана на часовника в началото на филма. -На втория ред е записана подобна последователност за показанието на часовника в края на филма. -На третия ред се въвежда продължителността на филма в часове, минути и секунди. -Часовникът е настроен така, че показва времето по 12-часова скала, а не по 24-часова. - -Изход: -На стандартния изход изведете всички възможни показания на часовника за началото и края на филма. -Всяка двойка с начален и краен час се извежда на един ред, като първо се извежда началното показание във формат hh:mm:ss, и след един интервал крайното показание в същия формат. -Ако такива показания на часовника не са възможни, да се изведе “Impossible”. - -Ограничения: -Продължителността на филма е не по-голяма 12 часа. - -Примери: - -Вход: -*25**6 -*10**2 -10 19 26 -Изход: -02:50:06 01:09:32 -02:50:16 01:09:42 -02:50:26 01:09:52 -12:50:06 11:09:32 -12:50:16 11:09:42 -12:50:26 11:09:52 - -Вход: -*95**6 -*21**2 -4 12 6 -Изход: -Impossible diff --git a/pract_SI/Pract. 03/Solutions/task1.cpp b/pract_SI/Pract. 03/Solutions/task1.cpp new file mode 100644 index 0000000..ae955a8 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task1.cpp @@ -0,0 +1,19 @@ +#include "pch.h" +#include + +using namespace std; + +int main() +{ + unsigned long long number; + cin >> number; + + for (int i = 1; i <= number; i++) + { + for (int j = 1; j <= i; j++) + cout << j; + cout << endl; + } + + return 0; +} diff --git a/pract_SI/Pract. 03/Solutions/task2.cpp b/pract_SI/Pract. 03/Solutions/task2.cpp new file mode 100644 index 0000000..b3e970d --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task2.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() +{ + unsigned long long number; + cin >> number; + + for (unsigned long long x = 1, y = number; x < number; x++) + { + cout << "x = " << x << " " + << "y = " << --y << endl; + } + + return 0; +} diff --git a/pract_SI/Pract. 03/Solutions/task3.cpp b/pract_SI/Pract. 03/Solutions/task3.cpp new file mode 100644 index 0000000..a6a6362 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task3.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; +int main() +{ + unsigned long long oldNumber, newNumber; + + cout << "Enter a positive number: "; + cin >> oldNumber; + + oldNumber *= oldNumber; + newNumber = 0; + + while (oldNumber != 0) + { + newNumber = newNumber * 10 + oldNumber % 10; + oldNumber /= 10; + } + + cout << newNumber << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task4.cpp b/pract_SI/Pract. 03/Solutions/task4.cpp new file mode 100644 index 0000000..622b8a1 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task4.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +int main() +{ + unsigned int m, n; + cout << "Number of rows: "; + cin >> m; + cout << "Number of columns: "; + cin >> n; + + for (unsigned int i = 1; i <= m * n; i++) + { + cout << i << " "; + if (i % n == 0) + { + cout << endl; + } + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task5.cpp b/pract_SI/Pract. 03/Solutions/task5.cpp new file mode 100644 index 0000000..d6ac57c --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task5.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +int main() +{ + unsigned short number, guess; + unsigned int counter = 0; + + cout << "Enter a number between 0 and 100: "; + cin >> number; + if (number < 0 || number > 100) + { + cout << "Invalid input!\n"; + return 1; + } + + do + { + ++counter; + + cout << "Guess " << counter << ": "; + cin >> guess; + if (guess < 0 || guess > 100) + { + cout << "Invalid input!\n"; + return 2; + } + + if (guess < number) + { + cout << "The number you are looking for is greater than your guess!\n"; + } + else if (guess > number) + { + cout << "The number you are looking for is less than your guess!\n"; + } + } while (guess != number); + + cout << "You found the number in " << counter << " attempt(s)!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task6.cpp b/pract_SI/Pract. 03/Solutions/task6.cpp new file mode 100644 index 0000000..8d0beac --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task6.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +int main() +{ + unsigned int number = 0, input = 1; + + while(input != 0) + { + cout << "Enter a positive number: "; + cin >> input; + + number ^= input; + } + + cout << "The single number is " << number << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task7.cpp b/pract_SI/Pract. 03/Solutions/task7.cpp new file mode 100644 index 0000000..aa9194b --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task7.cpp @@ -0,0 +1,30 @@ +#include +#define LIMIT 5 +#define SEPARATOR " " + +using namespace std; + +//const short LIMIT = 5; +//const char SEPARATOR = ' '; + + +int main() +{ + unsigned long long N; + cin >> N; + + if (N < LIMIT) + return -1; + + for (int c = 1; c <= N; c++) { + for (int b = 1; b < c; b++) { + for (int a = 1; a < b; a++) { + if ((a * a) + (b * b) == (c * c)) { + cout << a << SEPARATOR << b << SEPARATOR << c << endl; + } + } + } + } + + return 0; +} diff --git a/pract_SI/Pract. 03/Solutions/task8.cpp b/pract_SI/Pract. 03/Solutions/task8.cpp new file mode 100644 index 0000000..3f32ebf --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task8.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +const short LOWERLIMIT = 2; +const short UPPERLIMIT = 9; +const char SEPARATOR = ' '; + +int main() +{ + short N; + char S; + cin >> N >> S; + + if (N < LOWERLIMIT || N > UPPERLIMIT) + return -1; //end program + + for (int i = 1; i <= N; i++) + { + for (int j = N - i; j > 0; j--) + cout << SEPARATOR; + + for (int k = 1; k < 2 * i; k++) + cout << S; + + cout << endl; + } + + for (int i = 1; i < N; i++) + { + for (int j = 1; j <= i; j++) + cout << SEPARATOR; + + for (int k = 1; k < 2 * (N - i); k++) + cout << S; + + cout << endl; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task9.cpp b/pract_SI/Pract. 03/Solutions/task9.cpp new file mode 100644 index 0000000..9f1f054 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task9.cpp @@ -0,0 +1,59 @@ +#include + +int main() { + + // по-нататък ще учим как се вкарват сложни данни, затова сега ще ги hardcode-нем в main-а + + int hoursOnesStart = 2, minutesTensStart = 5, secondsOnesStart = 6; + int hoursOnesFinal = 1, minutesTensFinal = 0, secondsOnesFinal = 2; + int hoursDelta = 10, minutesDelta = 19, secondsDelta = 26; + + for (size_t hoursTensStart = 0; hoursTensStart <= 1; ++hoursTensStart) + { + for (size_t minutesOnesStart = 0; minutesOnesStart <= 9; ++minutesOnesStart) + { + for (size_t secondsTensStart = 0; secondsTensStart <= 5; secondsTensStart++) + { + int hoursTemp = hoursTensStart * 10 + hoursOnesStart; + int minutesTemp = minutesTensStart * 10 + minutesOnesStart; + int secondsTemp = secondsTensStart * 10 + secondsOnesStart; + + secondsTemp += secondsDelta; + if (secondsTemp >= 60) { + minutesTemp += secondsTemp / 60; + secondsTemp %= 60; + } + + minutesTemp += minutesDelta; + if (minutesTemp >= 60) { + hoursTemp += minutesTemp / 60; + minutesTemp %= 60; + } + + hoursTemp += hoursDelta; + if (hoursTemp > 12) { + hoursTemp %= 12; + } + + bool hoursOnesMatch = hoursTemp % 10 == hoursOnesFinal, + minutesTensMatch = minutesTemp / 10 == minutesTensFinal, + secondsOnesMatch = secondsTemp % 10 == secondsOnesFinal; + + if (hoursOnesMatch && minutesTensMatch && secondsOnesMatch) { + int hoursTensFinal = hoursTemp / 10, + minutesOnesFinal = minutesTemp % 10, + secondsTensFinal = secondsTemp / 10; + + std::cout << hoursTensStart << hoursOnesStart << ':' + << minutesTensStart << minutesOnesStart << ':' + << secondsTensStart << secondsOnesStart << ' ' + << hoursTensFinal << hoursOnesFinal << ':' + << minutesTensFinal << minutesOnesFinal << ':' + << secondsTensFinal << secondsOnesFinal << '\n'; + } + } + } + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Startup_tasks.txt b/pract_SI/Pract. 03/Startup_tasks.txt new file mode 100644 index 0000000..8ee6d58 --- /dev/null +++ b/pract_SI/Pract. 03/Startup_tasks.txt @@ -0,0 +1,7 @@ +1.Напишете програма , която приема като вход N лева.Да се отпечата как бихме разпределили сумата на банкноти, +така че да имаме минимален брой банкноти. (Да не се използват условни оператори и цикли) +Пояснение: Нека да приемем, че имаме банкноти с 1лв и 2лв. + +2.Напишете програма, която приема като вход цяло положително число V, което ще отговаря на скорост. +Програмата да отпечатва колко е глобата от КАТ, а ако няма глоба следното съобщение "No speedticket". +(https://stamatovandpartners.com/elektronen-fish-za-previshena-skorost/) \ No newline at end of file diff --git a/pract_SI/Pract. 03/Tasks3.txt b/pract_SI/Pract. 03/Tasks3.txt new file mode 100644 index 0000000..64c5c4c --- /dev/null +++ b/pract_SI/Pract. 03/Tasks3.txt @@ -0,0 +1,131 @@ +#Никола Светославов - task3 + +## Задачи + +1.Да се напише програма, която приема естествено число n и изписва стълба от 1 до n + +Пример +Вход: +5 +Изход: +1 +12 +123 +1234 +12345 + +2.Да се състави програма, която по въведено естествено число n да изведе всички естествени решения на уравнението x + y = n. + +Пример +Вход: +4 +Изход: +x = 1 y = 3 +x = 2 y = 2 +x = 3 y = 1 + + +3.Напишете програма, която по въведено цяло положително число, извежда квадратът на това число, но в обратен ред, като водещите нули се игнорират. + +Пример +Вход: +10 +Изход: +1 + +Вход: +25 +Изход: +526 + +4.Напишете програма, която приема от потребителя две цели положителни числа - *m* и *n*. + Програмата да отпечата числатаот 1 до m*n, като на всеки ред има по *n* числа (тоест ще отпечатате *m* реда). + Печатайте числата по редове: + +Пример +Вход: +2 3 +Изход: +1 2 3 +4 5 6 + +5.Напишете проста игра, в която първо се въвежда цяло число в интервала [0;100] и в последствие се въвеждат цели числа + (предположения), като за всяко се казва дали е по - малко или по - голямо от първоначално ваведеното. + Tова продължава до въвеждане на число, равно на първоначалното. Програмата да отпечата и броят направени предположения. + +6.Напишете програма, която иска от потребителя поредица от цели числа по - големи от 0. + Въвеждането приключва с въвеждане на 0. Гарантирано е, че всяко от числата е въведено **точно два пъти** освен едно, + което е въведено **точно веднъж**. Програмата да изведе кое е това число. + +7.Да се състави програма, която по въведено естествено число N намира и отпечатва всички тройки естествени числа a, b и c, + не по-големи от N, които могат да бъдат страни на правоъгълен триъгълник. + +Пример +Вход: +11 +Изход +3 4 5 +6 8 10 + +8.Напишете програма, която иска от потребителя вход цифра N[2;9] и символ S.Програмата да извежда фигура съставена от символа във вид на ромб, както е показано на примерите. + +Пример +Вход: +5 * +Изход + * + *** + ***** + ******* +********* + ******* + ***** + *** + * + +*Бонус* +Задача ЕЛЕКТРОНЕН ЧАСОВНИК +В големия нов МОЛ в града на програмистите се повредили част от цифрите на електронния часовник. +Повредени били първата цифра от числото, което показва часовете, втората цифра на числото, което показва минутите и първата цифра на числото, което показва секундите. +Вместо тях на екрана се появявал знака *. +Когато Коко и приятелите му ходели на кино, те не успявали да преценят точно колко е часа. +Все пак, момчетата си създали система за изчисление, която приблизително точно им показвало времето. +Те успявали да предвидят колко е показвал часовника в началото и края на филма, в случай че знаят точно колко време е минало. +Срещу името на всеки филм на входа на киното е дадено неговото времетраене в часове, минути и секунди. +Пресмятанията доста затрудняват момчетата и затова на тях ще им е по-удобно това да се прави с компютърна програма. +Те не разбират много от програмиране и затова вие трябва да напишете програма clock, която помага на Коко и приятелите му. + +Вход: +На първия ред на стандартния вход е записана последователност от цифри и знака *, която показва какво се вижда на екрана на часовника в началото на филма. +На втория ред е записана подобна последователност за показанието на часовника в края на филма. +На третия ред се въвежда продължителността на филма в часове, минути и секунди. +Часовникът е настроен така, че показва времето по 12-часова скала, а не по 24-часова. + +Изход: +На стандартния изход изведете всички възможни показания на часовника за началото и края на филма. +Всяка двойка с начален и краен час се извежда на един ред, като първо се извежда началното показание във формат hh:mm:ss, и след един интервал крайното показание в същия формат. +Ако такива показания на часовника не са възможни, да се изведе “Impossible”. + +Ограничения: +Продължителността на филма е не по-голяма 12 часа. + +Примери: + +Вход: +*25**6 +*10**2 +10 19 26 +Изход: +02:50:06 01:09:32 +02:50:16 01:09:42 +02:50:26 01:09:52 +12:50:06 11:09:32 +12:50:16 11:09:42 +12:50:26 11:09:52 + +Вход: +*95**6 +*21**2 +4 12 6 +Изход: +Impossible -- cgit v1.3.1-23-gd82d From 653bd0b31519cf279e402fd177a40bafbcffc897 Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Thu, 28 Oct 2021 17:37:38 +0300 Subject: Update Pract 01-03. Rename --- pract_SI/Pract. 01/Solutions/task1.cpp | 12 +++++ pract_SI/Pract. 01/Solutions/task2.cpp | 17 ++++++++ pract_SI/Pract. 01/Solutions/task3.cpp | 16 +++++++ pract_SI/Pract. 01/Solutions/task4.cpp | 23 ++++++++++ pract_SI/Pract. 01/Solutions/task5.cpp | 16 +++++++ pract_SI/Pract. 02/Solutions/task1.cpp | 20 +++++++++ pract_SI/Pract. 02/Solutions/task2.cpp | 29 ++++++++++++ .../Pract. 02/Solutions/task3 - no EPSILON.cpp | 23 ++++++++++ .../Pract. 02/Solutions/task3 - with EPSILON.cpp | 24 ++++++++++ pract_SI/Pract. 02/Solutions/task4.cpp | 26 +++++++++++ pract_SI/Pract. 02/Solutions/task5.cpp | 51 ++++++++++++++++++++++ pract_SI/Pract. 02/Solutions/task6.cpp | 42 ++++++++++++++++++ pract_SI/Pract. 02/Solutions/task7.cpp | 44 +++++++++++++++++++ 13 files changed, 343 insertions(+) create mode 100644 pract_SI/Pract. 01/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task2.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task3.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task2.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task6.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task7.cpp diff --git a/pract_SI/Pract. 01/Solutions/task1.cpp b/pract_SI/Pract. 01/Solutions/task1.cpp new file mode 100644 index 0000000..54a1902 --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task1.cpp @@ -0,0 +1,12 @@ +#include +#include +using namespace std; +int main() +{ + string name; + cout << "What is your name?\n"; + cin >> name; + cout << "Hello, " << name << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task2.cpp b/pract_SI/Pract. 01/Solutions/task2.cpp new file mode 100644 index 0000000..554653d --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task2.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +int main() +{ + double x, y; + + cout << "First side: "; + cin >> x; + + cout << "Second side: "; + cin >> y; + + cout << "Parameter: " << 2 * (x + y) << endl; + cout << "Area: " << x * y << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task3.cpp b/pract_SI/Pract. 01/Solutions/task3.cpp new file mode 100644 index 0000000..830348b --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task3.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; +int main() +{ + double a, b; + + cout << "First number: "; + cin >> a; + + cout << "Second number: "; + cin >> b; + + cout << boolalpha << (a < b) << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task4.cpp b/pract_SI/Pract. 01/Solutions/task4.cpp new file mode 100644 index 0000000..b4829b4 --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task4.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace std; +int main() +{ + double x1, y1, x2, y2; + + cout << "x1: "; + cin >> x1; + + cout << "y1: "; + cin >> y1; + + cout << "x2: "; + cin >> x2; + + cout << "y2: "; + cin >> y2; + + cout << round(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) * 100) / 100 << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task5.cpp b/pract_SI/Pract. 01/Solutions/task5.cpp new file mode 100644 index 0000000..931178d --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task5.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +using namespace std; +int main() +{ + string card_number; + + cout << "Card number: "; + cin >> card_number; + + cout << "Hidden card number: " << setfill('X') << setw(13) + << card_number[12] << card_number[13] << card_number[14] << card_number[15] << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task1.cpp b/pract_SI/Pract. 02/Solutions/task1.cpp new file mode 100644 index 0000000..3a60fad --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task1.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; +int main() +{ + int year; + + cout << "Enter an year to check: "; + cin >> year; + + cout << year << " is"; + + if (!(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))) + { + cout << " not"; + } + + cout << " leap!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task2.cpp b/pract_SI/Pract. 02/Solutions/task2.cpp new file mode 100644 index 0000000..a1ddcf8 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task2.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main() +{ + char inputCharacter; + + cout << "Enter a character to test: "; + cin >> inputCharacter; + + cout << inputCharacter << " is "; + if (inputCharacter == 'a' || inputCharacter == 'e' || inputCharacter == 'i' || inputCharacter == 'o' || inputCharacter == 'u' || + inputCharacter == 'A' || inputCharacter == 'E' || inputCharacter == 'I' || inputCharacter == 'O' || inputCharacter == 'U') + { + cout << "a vowel!\n"; + } + else + { + if ((inputCharacter >= 'a' && inputCharacter <= 'z') || (inputCharacter >= 'A' && inputCharacter <= 'Z')) + { + cout << "a consonant!\n"; + } + else + { + cout << "is not a letter from the English alphabet!\n"; + } + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp new file mode 100644 index 0000000..6c9f832 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace std; +int main() +{ + double x, y; + + cout << "Enter the first number: "; + cin >> x; + + cout << "Enter the second number: "; + cin >> y; + + if (fabs(x - y) < 0.000001) + { + cout << "Numbers must be different!\n"; + return 1; + } + + cout << (x < y ? y : x) << " is the greater number!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp new file mode 100644 index 0000000..dcd5f88 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main() +{ + double num1, num2; + + cout << "Enter the first number: "; + cin >> num1; + + cout << "Enter the second number: "; + cin >> num2; + + if (fabs(num1 - num2) <= DBL_EPSILON * fabs(num1)) + { + cout << "Numbers must be different!\n"; + return 1; + } + + cout << (num1 > num2 ? "First" : "Second") << " is the greater number!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task4.cpp b/pract_SI/Pract. 02/Solutions/task4.cpp new file mode 100644 index 0000000..acb471c --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task4.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() +{ + double a, b, c; + + cout << "First side: "; + cin >> a; + + cout << "Second side: "; + cin >> b; + + cout << "Third side: "; + cin >> c; + + if ((a + b > c) && (a + c > b) && (b + c > a)) + { + cout << "Triangle is valid.\n"; + } + else + { + cout << "Triangle is not valid.\n"; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task5.cpp b/pract_SI/Pract. 02/Solutions/task5.cpp new file mode 100644 index 0000000..419d6d4 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task5.cpp @@ -0,0 +1,51 @@ +#include +#include +using namespace std; +int main() +{ + double a, b, c; + double root1, root2, imaginary; + double discriminant; + + cout << "Finding the root of the equation a * x^2 + b * x + c = 0\n"; + + cout << "Enter the value of a: "; + cin >> a; + + if (a < 0.00000001) + { + cout << "If a is 0, then this is not a quadratic equation!\n"; + return 1; + } + + cout << "Enter the value of b: "; + cin >> b; + + cout << "Enter the value of c: "; + cin >> c; + + discriminant = (b * b) - (4 * a * c); + + if (discriminant > 0) + { + root1 = (-b + sqrt(discriminant)) / (2 * a); + root2 = (-b - sqrt(discriminant)) / (2 * a); + + cout << "Two distinct and real roots exist: " << root1 << " and " << root2 << endl; + } + else if (discriminant == 0) + { + root1 = root2 = -b / (2 * a); + + cout << "Two equal and real roots exist: " << root1 << " and " << root2 << endl; + } + else if (discriminant < 0) + { + root1 = root2 = -b / (2 * a); + imaginary = sqrt(-discriminant) / (2 * a); + + cout << "Two distinct complex roots exist: " << root1 << "+" << imaginary << "i and " << root2 << "-" << imaginary << "i\n"; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task6.cpp b/pract_SI/Pract. 02/Solutions/task6.cpp new file mode 100644 index 0000000..a7484b2 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task6.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; +int main() +{ + double a, b; + char operation; + + cout << "Enter the first number: "; + cin >> a; + + cout << "Enter the second number: "; + cin >> b; + + cout << "Choose operation: +, -, / or *: "; + cin >> operation; + + switch (operation) + { + case '+': + cout << "Result: " << a + b << endl; + break; + case '-': + cout << "Result: " << a - b << endl; + break; + case '*': + cout << "Result: " << a * b << endl; + break; + case '/': + if (b < 0.0000001) + { + cout << "You can not divide by zero!\n"; + return 1; + } + cout << "Result: " << a / b << endl; + break; + default: + cout << "Invalid operation!\n"; + break; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task7.cpp b/pract_SI/Pract. 02/Solutions/task7.cpp new file mode 100644 index 0000000..3c22a83 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task7.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; +int main() +{ + // you can use int as well, but do you really need something as big as int? + short number; + unsigned char digit1, digit2, digit3, digit4, number1, number2; + + cout << "Enter a 4-digit number: "; + cin >> number; + + if (number < 1000 || number > 10000) + { + cout << "The input must be a 4-digit number!\n"; + return 1; + } + + digit1 = number / 1000; + digit2 = number / 100 % 10; + digit3 = number / 10 % 10; + digit4 = number % 10; + + number1 = digit1 * 10 + digit4; + number2 = digit2 * 10 + digit3; + + if (number1 < number2) + { + cout << "less (" << (int)number1 << " < " << (int)number2 << ")\n"; + } + else + { + if (number1 == number2) + { + cout << "equal (" << (int)number1 << " = " << (int)number2 << ")\n"; + } + else + { + cout << "greater (" << (int)number1 << " > " << (int)number2 << ")\n"; + } + } + + + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From f61a51c13a36ccf11b26651787be079861c50ea4 Mon Sep 17 00:00:00 2001 From: Justsvetoslavov <50053338+Justsvetoslavov@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:38:38 +0300 Subject: Delete pract_SI directory --- pract_SI/Pract. 01/Solutions/task1.cpp | 12 -- pract_SI/Pract. 01/Solutions/task2.cpp | 17 --- pract_SI/Pract. 01/Solutions/task3.cpp | 16 --- pract_SI/Pract. 01/Solutions/task4.cpp | 23 ---- pract_SI/Pract. 01/Solutions/task5.cpp | 16 --- pract_SI/Pract. 02/Solutions/task1.cpp | 20 ---- pract_SI/Pract. 02/Solutions/task2.cpp | 29 ----- .../Pract. 02/Solutions/task3 - no EPSILON.cpp | 23 ---- .../Pract. 02/Solutions/task3 - with EPSILON.cpp | 24 ---- pract_SI/Pract. 02/Solutions/task4.cpp | 26 ---- pract_SI/Pract. 02/Solutions/task5.cpp | 51 -------- pract_SI/Pract. 02/Solutions/task6.cpp | 42 ------- pract_SI/Pract. 02/Solutions/task7.cpp | 44 ------- pract_SI/Pract. 03/Solutions/task1.cpp | 19 --- pract_SI/Pract. 03/Solutions/task2.cpp | 17 --- pract_SI/Pract. 03/Solutions/task3.cpp | 22 ---- pract_SI/Pract. 03/Solutions/task4.cpp | 21 ---- pract_SI/Pract. 03/Solutions/task5.cpp | 41 ------- pract_SI/Pract. 03/Solutions/task6.cpp | 18 --- pract_SI/Pract. 03/Solutions/task7.cpp | 30 ----- pract_SI/Pract. 03/Solutions/task8.cpp | 41 ------- pract_SI/Pract. 03/Solutions/task9.cpp | 59 ---------- pract_SI/Pract. 03/Startup_tasks.txt | 7 -- pract_SI/Pract. 03/Tasks3.txt | 131 --------------------- pract_SI/pract. 01/Tasks_1.txt | 20 ---- pract_SI/pract. 01/task1.cpp | 12 -- pract_SI/pract. 01/task2.cpp | 17 --- pract_SI/pract. 01/task3.cpp | 16 --- pract_SI/pract. 01/task4.cpp | 23 ---- pract_SI/pract. 01/task5.cpp | 16 --- pract_SI/pract. 02/Tasks_2.txt | 37 ------ pract_SI/pract. 02/task1.cpp | 20 ---- pract_SI/pract. 02/task2.cpp | 29 ----- pract_SI/pract. 02/task3 - no EPSILON.cpp | 23 ---- pract_SI/pract. 02/task3 - with EPSILON.cpp | 24 ---- pract_SI/pract. 02/task4.cpp | 26 ---- pract_SI/pract. 02/task5.cpp | 51 -------- pract_SI/pract. 02/task6.cpp | 42 ------- pract_SI/pract. 02/task7.cpp | 44 ------- 39 files changed, 1149 deletions(-) delete mode 100644 pract_SI/Pract. 01/Solutions/task1.cpp delete mode 100644 pract_SI/Pract. 01/Solutions/task2.cpp delete mode 100644 pract_SI/Pract. 01/Solutions/task3.cpp delete mode 100644 pract_SI/Pract. 01/Solutions/task4.cpp delete mode 100644 pract_SI/Pract. 01/Solutions/task5.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task1.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task2.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task4.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task5.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task6.cpp delete mode 100644 pract_SI/Pract. 02/Solutions/task7.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task1.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task2.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task3.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task4.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task5.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task6.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task7.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task8.cpp delete mode 100644 pract_SI/Pract. 03/Solutions/task9.cpp delete mode 100644 pract_SI/Pract. 03/Startup_tasks.txt delete mode 100644 pract_SI/Pract. 03/Tasks3.txt delete mode 100644 pract_SI/pract. 01/Tasks_1.txt delete mode 100644 pract_SI/pract. 01/task1.cpp delete mode 100644 pract_SI/pract. 01/task2.cpp delete mode 100644 pract_SI/pract. 01/task3.cpp delete mode 100644 pract_SI/pract. 01/task4.cpp delete mode 100644 pract_SI/pract. 01/task5.cpp delete mode 100644 pract_SI/pract. 02/Tasks_2.txt delete mode 100644 pract_SI/pract. 02/task1.cpp delete mode 100644 pract_SI/pract. 02/task2.cpp delete mode 100644 pract_SI/pract. 02/task3 - no EPSILON.cpp delete mode 100644 pract_SI/pract. 02/task3 - with EPSILON.cpp delete mode 100644 pract_SI/pract. 02/task4.cpp delete mode 100644 pract_SI/pract. 02/task5.cpp delete mode 100644 pract_SI/pract. 02/task6.cpp delete mode 100644 pract_SI/pract. 02/task7.cpp diff --git a/pract_SI/Pract. 01/Solutions/task1.cpp b/pract_SI/Pract. 01/Solutions/task1.cpp deleted file mode 100644 index 54a1902..0000000 --- a/pract_SI/Pract. 01/Solutions/task1.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - string name; - cout << "What is your name?\n"; - cin >> name; - cout << "Hello, " << name << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task2.cpp b/pract_SI/Pract. 01/Solutions/task2.cpp deleted file mode 100644 index 554653d..0000000 --- a/pract_SI/Pract. 01/Solutions/task2.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -using namespace std; -int main() -{ - double x, y; - - cout << "First side: "; - cin >> x; - - cout << "Second side: "; - cin >> y; - - cout << "Parameter: " << 2 * (x + y) << endl; - cout << "Area: " << x * y << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task3.cpp b/pract_SI/Pract. 01/Solutions/task3.cpp deleted file mode 100644 index 830348b..0000000 --- a/pract_SI/Pract. 01/Solutions/task3.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; -int main() -{ - double a, b; - - cout << "First number: "; - cin >> a; - - cout << "Second number: "; - cin >> b; - - cout << boolalpha << (a < b) << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task4.cpp b/pract_SI/Pract. 01/Solutions/task4.cpp deleted file mode 100644 index b4829b4..0000000 --- a/pract_SI/Pract. 01/Solutions/task4.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - double x1, y1, x2, y2; - - cout << "x1: "; - cin >> x1; - - cout << "y1: "; - cin >> y1; - - cout << "x2: "; - cin >> x2; - - cout << "y2: "; - cin >> y2; - - cout << round(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) * 100) / 100 << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task5.cpp b/pract_SI/Pract. 01/Solutions/task5.cpp deleted file mode 100644 index 931178d..0000000 --- a/pract_SI/Pract. 01/Solutions/task5.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -using namespace std; -int main() -{ - string card_number; - - cout << "Card number: "; - cin >> card_number; - - cout << "Hidden card number: " << setfill('X') << setw(13) - << card_number[12] << card_number[13] << card_number[14] << card_number[15] << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task1.cpp b/pract_SI/Pract. 02/Solutions/task1.cpp deleted file mode 100644 index 3a60fad..0000000 --- a/pract_SI/Pract. 02/Solutions/task1.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -using namespace std; -int main() -{ - int year; - - cout << "Enter an year to check: "; - cin >> year; - - cout << year << " is"; - - if (!(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))) - { - cout << " not"; - } - - cout << " leap!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task2.cpp b/pract_SI/Pract. 02/Solutions/task2.cpp deleted file mode 100644 index a1ddcf8..0000000 --- a/pract_SI/Pract. 02/Solutions/task2.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; -int main() -{ - char inputCharacter; - - cout << "Enter a character to test: "; - cin >> inputCharacter; - - cout << inputCharacter << " is "; - if (inputCharacter == 'a' || inputCharacter == 'e' || inputCharacter == 'i' || inputCharacter == 'o' || inputCharacter == 'u' || - inputCharacter == 'A' || inputCharacter == 'E' || inputCharacter == 'I' || inputCharacter == 'O' || inputCharacter == 'U') - { - cout << "a vowel!\n"; - } - else - { - if ((inputCharacter >= 'a' && inputCharacter <= 'z') || (inputCharacter >= 'A' && inputCharacter <= 'Z')) - { - cout << "a consonant!\n"; - } - else - { - cout << "is not a letter from the English alphabet!\n"; - } - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp deleted file mode 100644 index 6c9f832..0000000 --- a/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - double x, y; - - cout << "Enter the first number: "; - cin >> x; - - cout << "Enter the second number: "; - cin >> y; - - if (fabs(x - y) < 0.000001) - { - cout << "Numbers must be different!\n"; - return 1; - } - - cout << (x < y ? y : x) << " is the greater number!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp deleted file mode 100644 index dcd5f88..0000000 --- a/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - double num1, num2; - - cout << "Enter the first number: "; - cin >> num1; - - cout << "Enter the second number: "; - cin >> num2; - - if (fabs(num1 - num2) <= DBL_EPSILON * fabs(num1)) - { - cout << "Numbers must be different!\n"; - return 1; - } - - cout << (num1 > num2 ? "First" : "Second") << " is the greater number!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task4.cpp b/pract_SI/Pract. 02/Solutions/task4.cpp deleted file mode 100644 index acb471c..0000000 --- a/pract_SI/Pract. 02/Solutions/task4.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int main() -{ - double a, b, c; - - cout << "First side: "; - cin >> a; - - cout << "Second side: "; - cin >> b; - - cout << "Third side: "; - cin >> c; - - if ((a + b > c) && (a + c > b) && (b + c > a)) - { - cout << "Triangle is valid.\n"; - } - else - { - cout << "Triangle is not valid.\n"; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task5.cpp b/pract_SI/Pract. 02/Solutions/task5.cpp deleted file mode 100644 index 419d6d4..0000000 --- a/pract_SI/Pract. 02/Solutions/task5.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - double a, b, c; - double root1, root2, imaginary; - double discriminant; - - cout << "Finding the root of the equation a * x^2 + b * x + c = 0\n"; - - cout << "Enter the value of a: "; - cin >> a; - - if (a < 0.00000001) - { - cout << "If a is 0, then this is not a quadratic equation!\n"; - return 1; - } - - cout << "Enter the value of b: "; - cin >> b; - - cout << "Enter the value of c: "; - cin >> c; - - discriminant = (b * b) - (4 * a * c); - - if (discriminant > 0) - { - root1 = (-b + sqrt(discriminant)) / (2 * a); - root2 = (-b - sqrt(discriminant)) / (2 * a); - - cout << "Two distinct and real roots exist: " << root1 << " and " << root2 << endl; - } - else if (discriminant == 0) - { - root1 = root2 = -b / (2 * a); - - cout << "Two equal and real roots exist: " << root1 << " and " << root2 << endl; - } - else if (discriminant < 0) - { - root1 = root2 = -b / (2 * a); - imaginary = sqrt(-discriminant) / (2 * a); - - cout << "Two distinct complex roots exist: " << root1 << "+" << imaginary << "i and " << root2 << "-" << imaginary << "i\n"; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task6.cpp b/pract_SI/Pract. 02/Solutions/task6.cpp deleted file mode 100644 index a7484b2..0000000 --- a/pract_SI/Pract. 02/Solutions/task6.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -using namespace std; -int main() -{ - double a, b; - char operation; - - cout << "Enter the first number: "; - cin >> a; - - cout << "Enter the second number: "; - cin >> b; - - cout << "Choose operation: +, -, / or *: "; - cin >> operation; - - switch (operation) - { - case '+': - cout << "Result: " << a + b << endl; - break; - case '-': - cout << "Result: " << a - b << endl; - break; - case '*': - cout << "Result: " << a * b << endl; - break; - case '/': - if (b < 0.0000001) - { - cout << "You can not divide by zero!\n"; - return 1; - } - cout << "Result: " << a / b << endl; - break; - default: - cout << "Invalid operation!\n"; - break; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task7.cpp b/pract_SI/Pract. 02/Solutions/task7.cpp deleted file mode 100644 index 3c22a83..0000000 --- a/pract_SI/Pract. 02/Solutions/task7.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -using namespace std; -int main() -{ - // you can use int as well, but do you really need something as big as int? - short number; - unsigned char digit1, digit2, digit3, digit4, number1, number2; - - cout << "Enter a 4-digit number: "; - cin >> number; - - if (number < 1000 || number > 10000) - { - cout << "The input must be a 4-digit number!\n"; - return 1; - } - - digit1 = number / 1000; - digit2 = number / 100 % 10; - digit3 = number / 10 % 10; - digit4 = number % 10; - - number1 = digit1 * 10 + digit4; - number2 = digit2 * 10 + digit3; - - if (number1 < number2) - { - cout << "less (" << (int)number1 << " < " << (int)number2 << ")\n"; - } - else - { - if (number1 == number2) - { - cout << "equal (" << (int)number1 << " = " << (int)number2 << ")\n"; - } - else - { - cout << "greater (" << (int)number1 << " > " << (int)number2 << ")\n"; - } - } - - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task1.cpp b/pract_SI/Pract. 03/Solutions/task1.cpp deleted file mode 100644 index ae955a8..0000000 --- a/pract_SI/Pract. 03/Solutions/task1.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "pch.h" -#include - -using namespace std; - -int main() -{ - unsigned long long number; - cin >> number; - - for (int i = 1; i <= number; i++) - { - for (int j = 1; j <= i; j++) - cout << j; - cout << endl; - } - - return 0; -} diff --git a/pract_SI/Pract. 03/Solutions/task2.cpp b/pract_SI/Pract. 03/Solutions/task2.cpp deleted file mode 100644 index b3e970d..0000000 --- a/pract_SI/Pract. 03/Solutions/task2.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -using namespace std; - -int main() -{ - unsigned long long number; - cin >> number; - - for (unsigned long long x = 1, y = number; x < number; x++) - { - cout << "x = " << x << " " - << "y = " << --y << endl; - } - - return 0; -} diff --git a/pract_SI/Pract. 03/Solutions/task3.cpp b/pract_SI/Pract. 03/Solutions/task3.cpp deleted file mode 100644 index a6a6362..0000000 --- a/pract_SI/Pract. 03/Solutions/task3.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned long long oldNumber, newNumber; - - cout << "Enter a positive number: "; - cin >> oldNumber; - - oldNumber *= oldNumber; - newNumber = 0; - - while (oldNumber != 0) - { - newNumber = newNumber * 10 + oldNumber % 10; - oldNumber /= 10; - } - - cout << newNumber << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task4.cpp b/pract_SI/Pract. 03/Solutions/task4.cpp deleted file mode 100644 index 622b8a1..0000000 --- a/pract_SI/Pract. 03/Solutions/task4.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned int m, n; - cout << "Number of rows: "; - cin >> m; - cout << "Number of columns: "; - cin >> n; - - for (unsigned int i = 1; i <= m * n; i++) - { - cout << i << " "; - if (i % n == 0) - { - cout << endl; - } - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task5.cpp b/pract_SI/Pract. 03/Solutions/task5.cpp deleted file mode 100644 index d6ac57c..0000000 --- a/pract_SI/Pract. 03/Solutions/task5.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned short number, guess; - unsigned int counter = 0; - - cout << "Enter a number between 0 and 100: "; - cin >> number; - if (number < 0 || number > 100) - { - cout << "Invalid input!\n"; - return 1; - } - - do - { - ++counter; - - cout << "Guess " << counter << ": "; - cin >> guess; - if (guess < 0 || guess > 100) - { - cout << "Invalid input!\n"; - return 2; - } - - if (guess < number) - { - cout << "The number you are looking for is greater than your guess!\n"; - } - else if (guess > number) - { - cout << "The number you are looking for is less than your guess!\n"; - } - } while (guess != number); - - cout << "You found the number in " << counter << " attempt(s)!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task6.cpp b/pract_SI/Pract. 03/Solutions/task6.cpp deleted file mode 100644 index 8d0beac..0000000 --- a/pract_SI/Pract. 03/Solutions/task6.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; -int main() -{ - unsigned int number = 0, input = 1; - - while(input != 0) - { - cout << "Enter a positive number: "; - cin >> input; - - number ^= input; - } - - cout << "The single number is " << number << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task7.cpp b/pract_SI/Pract. 03/Solutions/task7.cpp deleted file mode 100644 index aa9194b..0000000 --- a/pract_SI/Pract. 03/Solutions/task7.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#define LIMIT 5 -#define SEPARATOR " " - -using namespace std; - -//const short LIMIT = 5; -//const char SEPARATOR = ' '; - - -int main() -{ - unsigned long long N; - cin >> N; - - if (N < LIMIT) - return -1; - - for (int c = 1; c <= N; c++) { - for (int b = 1; b < c; b++) { - for (int a = 1; a < b; a++) { - if ((a * a) + (b * b) == (c * c)) { - cout << a << SEPARATOR << b << SEPARATOR << c << endl; - } - } - } - } - - return 0; -} diff --git a/pract_SI/Pract. 03/Solutions/task8.cpp b/pract_SI/Pract. 03/Solutions/task8.cpp deleted file mode 100644 index 3f32ebf..0000000 --- a/pract_SI/Pract. 03/Solutions/task8.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; - -const short LOWERLIMIT = 2; -const short UPPERLIMIT = 9; -const char SEPARATOR = ' '; - -int main() -{ - short N; - char S; - cin >> N >> S; - - if (N < LOWERLIMIT || N > UPPERLIMIT) - return -1; //end program - - for (int i = 1; i <= N; i++) - { - for (int j = N - i; j > 0; j--) - cout << SEPARATOR; - - for (int k = 1; k < 2 * i; k++) - cout << S; - - cout << endl; - } - - for (int i = 1; i < N; i++) - { - for (int j = 1; j <= i; j++) - cout << SEPARATOR; - - for (int k = 1; k < 2 * (N - i); k++) - cout << S; - - cout << endl; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task9.cpp b/pract_SI/Pract. 03/Solutions/task9.cpp deleted file mode 100644 index 9f1f054..0000000 --- a/pract_SI/Pract. 03/Solutions/task9.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -int main() { - - // по-нататък ще учим как се вкарват сложни данни, затова сега ще ги hardcode-нем в main-а - - int hoursOnesStart = 2, minutesTensStart = 5, secondsOnesStart = 6; - int hoursOnesFinal = 1, minutesTensFinal = 0, secondsOnesFinal = 2; - int hoursDelta = 10, minutesDelta = 19, secondsDelta = 26; - - for (size_t hoursTensStart = 0; hoursTensStart <= 1; ++hoursTensStart) - { - for (size_t minutesOnesStart = 0; minutesOnesStart <= 9; ++minutesOnesStart) - { - for (size_t secondsTensStart = 0; secondsTensStart <= 5; secondsTensStart++) - { - int hoursTemp = hoursTensStart * 10 + hoursOnesStart; - int minutesTemp = minutesTensStart * 10 + minutesOnesStart; - int secondsTemp = secondsTensStart * 10 + secondsOnesStart; - - secondsTemp += secondsDelta; - if (secondsTemp >= 60) { - minutesTemp += secondsTemp / 60; - secondsTemp %= 60; - } - - minutesTemp += minutesDelta; - if (minutesTemp >= 60) { - hoursTemp += minutesTemp / 60; - minutesTemp %= 60; - } - - hoursTemp += hoursDelta; - if (hoursTemp > 12) { - hoursTemp %= 12; - } - - bool hoursOnesMatch = hoursTemp % 10 == hoursOnesFinal, - minutesTensMatch = minutesTemp / 10 == minutesTensFinal, - secondsOnesMatch = secondsTemp % 10 == secondsOnesFinal; - - if (hoursOnesMatch && minutesTensMatch && secondsOnesMatch) { - int hoursTensFinal = hoursTemp / 10, - minutesOnesFinal = minutesTemp % 10, - secondsTensFinal = secondsTemp / 10; - - std::cout << hoursTensStart << hoursOnesStart << ':' - << minutesTensStart << minutesOnesStart << ':' - << secondsTensStart << secondsOnesStart << ' ' - << hoursTensFinal << hoursOnesFinal << ':' - << minutesTensFinal << minutesOnesFinal << ':' - << secondsTensFinal << secondsOnesFinal << '\n'; - } - } - } - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Startup_tasks.txt b/pract_SI/Pract. 03/Startup_tasks.txt deleted file mode 100644 index 8ee6d58..0000000 --- a/pract_SI/Pract. 03/Startup_tasks.txt +++ /dev/null @@ -1,7 +0,0 @@ -1.Напишете програма , която приема като вход N лева.Да се отпечата как бихме разпределили сумата на банкноти, -така че да имаме минимален брой банкноти. (Да не се използват условни оператори и цикли) -Пояснение: Нека да приемем, че имаме банкноти с 1лв и 2лв. - -2.Напишете програма, която приема като вход цяло положително число V, което ще отговаря на скорост. -Програмата да отпечатва колко е глобата от КАТ, а ако няма глоба следното съобщение "No speedticket". -(https://stamatovandpartners.com/elektronen-fish-za-previshena-skorost/) \ No newline at end of file diff --git a/pract_SI/Pract. 03/Tasks3.txt b/pract_SI/Pract. 03/Tasks3.txt deleted file mode 100644 index 64c5c4c..0000000 --- a/pract_SI/Pract. 03/Tasks3.txt +++ /dev/null @@ -1,131 +0,0 @@ -#Никола Светославов - task3 - -## Задачи - -1.Да се напише програма, която приема естествено число n и изписва стълба от 1 до n - -Пример -Вход: -5 -Изход: -1 -12 -123 -1234 -12345 - -2.Да се състави програма, която по въведено естествено число n да изведе всички естествени решения на уравнението x + y = n. - -Пример -Вход: -4 -Изход: -x = 1 y = 3 -x = 2 y = 2 -x = 3 y = 1 - - -3.Напишете програма, която по въведено цяло положително число, извежда квадратът на това число, но в обратен ред, като водещите нули се игнорират. - -Пример -Вход: -10 -Изход: -1 - -Вход: -25 -Изход: -526 - -4.Напишете програма, която приема от потребителя две цели положителни числа - *m* и *n*. - Програмата да отпечата числатаот 1 до m*n, като на всеки ред има по *n* числа (тоест ще отпечатате *m* реда). - Печатайте числата по редове: - -Пример -Вход: -2 3 -Изход: -1 2 3 -4 5 6 - -5.Напишете проста игра, в която първо се въвежда цяло число в интервала [0;100] и в последствие се въвеждат цели числа - (предположения), като за всяко се казва дали е по - малко или по - голямо от първоначално ваведеното. - Tова продължава до въвеждане на число, равно на първоначалното. Програмата да отпечата и броят направени предположения. - -6.Напишете програма, която иска от потребителя поредица от цели числа по - големи от 0. - Въвеждането приключва с въвеждане на 0. Гарантирано е, че всяко от числата е въведено **точно два пъти** освен едно, - което е въведено **точно веднъж**. Програмата да изведе кое е това число. - -7.Да се състави програма, която по въведено естествено число N намира и отпечатва всички тройки естествени числа a, b и c, - не по-големи от N, които могат да бъдат страни на правоъгълен триъгълник. - -Пример -Вход: -11 -Изход -3 4 5 -6 8 10 - -8.Напишете програма, която иска от потребителя вход цифра N[2;9] и символ S.Програмата да извежда фигура съставена от символа във вид на ромб, както е показано на примерите. - -Пример -Вход: -5 * -Изход - * - *** - ***** - ******* -********* - ******* - ***** - *** - * - -*Бонус* -Задача ЕЛЕКТРОНЕН ЧАСОВНИК -В големия нов МОЛ в града на програмистите се повредили част от цифрите на електронния часовник. -Повредени били първата цифра от числото, което показва часовете, втората цифра на числото, което показва минутите и първата цифра на числото, което показва секундите. -Вместо тях на екрана се появявал знака *. -Когато Коко и приятелите му ходели на кино, те не успявали да преценят точно колко е часа. -Все пак, момчетата си създали система за изчисление, която приблизително точно им показвало времето. -Те успявали да предвидят колко е показвал часовника в началото и края на филма, в случай че знаят точно колко време е минало. -Срещу името на всеки филм на входа на киното е дадено неговото времетраене в часове, минути и секунди. -Пресмятанията доста затрудняват момчетата и затова на тях ще им е по-удобно това да се прави с компютърна програма. -Те не разбират много от програмиране и затова вие трябва да напишете програма clock, която помага на Коко и приятелите му. - -Вход: -На първия ред на стандартния вход е записана последователност от цифри и знака *, която показва какво се вижда на екрана на часовника в началото на филма. -На втория ред е записана подобна последователност за показанието на часовника в края на филма. -На третия ред се въвежда продължителността на филма в часове, минути и секунди. -Часовникът е настроен така, че показва времето по 12-часова скала, а не по 24-часова. - -Изход: -На стандартния изход изведете всички възможни показания на часовника за началото и края на филма. -Всяка двойка с начален и краен час се извежда на един ред, като първо се извежда началното показание във формат hh:mm:ss, и след един интервал крайното показание в същия формат. -Ако такива показания на часовника не са възможни, да се изведе “Impossible”. - -Ограничения: -Продължителността на филма е не по-голяма 12 часа. - -Примери: - -Вход: -*25**6 -*10**2 -10 19 26 -Изход: -02:50:06 01:09:32 -02:50:16 01:09:42 -02:50:26 01:09:52 -12:50:06 11:09:32 -12:50:16 11:09:42 -12:50:26 11:09:52 - -Вход: -*95**6 -*21**2 -4 12 6 -Изход: -Impossible diff --git a/pract_SI/pract. 01/Tasks_1.txt b/pract_SI/pract. 01/Tasks_1.txt deleted file mode 100644 index bb7ee2d..0000000 --- a/pract_SI/pract. 01/Tasks_1.txt +++ /dev/null @@ -1,20 +0,0 @@ -Никола Светославов - task1 - -## Задачи -1.Напишете програма, която пита потребителя за името му, след което отпечатва "Hello, <име>" - -2.Напишете програма, която подканя потребителя да въведе дължините на двете страни на правоъгълник - **като му извежда съобщение, например "Please enter the length of the first side:"** - Програмата да изведе периметърът и лицето на този правоъгълник. - **Страните може да не са цели числа!** - -3.Напишете програма, която взима две числа от стандартния вход и извежда *true* ако първото е по - малко от второто - и *false* в противен случай. - -4.Напишете програма, която приема от входа две двойки реални числа, отговарящи на две точки в равнината. - Да се отпечата растоянието между точките закръглено до 2-рия знак след десетичната запетая. - **Потърсете математическата формула в интернет ако не я знаете!** - -БОНУС:Напишете програма която приема номер на кредитна карта(16 цифри). - Програмата да изведе същият този номер, но със скрити първите 12 цифри (XXXXXXXXXXXX1234). -БОНУС:**Направете го без да записвате X-ове променлива и без да правите ```cout<<"XXXXXXXXXXXX"``` :)** diff --git a/pract_SI/pract. 01/task1.cpp b/pract_SI/pract. 01/task1.cpp deleted file mode 100644 index 54a1902..0000000 --- a/pract_SI/pract. 01/task1.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - string name; - cout << "What is your name?\n"; - cin >> name; - cout << "Hello, " << name << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 01/task2.cpp b/pract_SI/pract. 01/task2.cpp deleted file mode 100644 index 554653d..0000000 --- a/pract_SI/pract. 01/task2.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -using namespace std; -int main() -{ - double x, y; - - cout << "First side: "; - cin >> x; - - cout << "Second side: "; - cin >> y; - - cout << "Parameter: " << 2 * (x + y) << endl; - cout << "Area: " << x * y << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 01/task3.cpp b/pract_SI/pract. 01/task3.cpp deleted file mode 100644 index 830348b..0000000 --- a/pract_SI/pract. 01/task3.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; -int main() -{ - double a, b; - - cout << "First number: "; - cin >> a; - - cout << "Second number: "; - cin >> b; - - cout << boolalpha << (a < b) << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 01/task4.cpp b/pract_SI/pract. 01/task4.cpp deleted file mode 100644 index b4829b4..0000000 --- a/pract_SI/pract. 01/task4.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - double x1, y1, x2, y2; - - cout << "x1: "; - cin >> x1; - - cout << "y1: "; - cin >> y1; - - cout << "x2: "; - cin >> x2; - - cout << "y2: "; - cin >> y2; - - cout << round(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) * 100) / 100 << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 01/task5.cpp b/pract_SI/pract. 01/task5.cpp deleted file mode 100644 index 576bf2e..0000000 --- a/pract_SI/pract. 01/task5.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -using namespace std; -int main() -{ - string card_number;; - - cout << "Card number: "; - cin >> card_number; - - cout << "Hidden card number: " << setfill('X') << setw(13) - << card_number[12] << card_number[13] << card_number[14] << card_number[15] << endl; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/Tasks_2.txt b/pract_SI/pract. 02/Tasks_2.txt deleted file mode 100644 index a419241..0000000 --- a/pract_SI/pract. 02/Tasks_2.txt +++ /dev/null @@ -1,37 +0,0 @@ -#Никола Светославов - task2 - -## Задачи - -1. Напишете програма,която проверява дали въведена от потребителя година е високосна. - **Проверете сами кои години се считат за високосни** - -2. Напишете програма, която приема един символ от входа и проверява дали: - - * този символ е буква от латинската азбука; - * ако да, дали тази буква е гласна или съгласна. - - **Програмата да работи както за малки, така и за главни букви** - -3. Напишете програма, която приема две **различни** числа и казва кое е по голямо. - **Използвайте тернарен оператор** - -4. Напишете програма, която приема от входа три числа - страни на триъгълник. - Програмата да проверява дали това е валиден триъгълник. - -5. Напишете програма, която намира корените на квадратно уравнение. - За целта потребителя да въведе коефицентите на уравнението - *a*, *b*, и *c* - при уравнение с вид *a \* x^2 + b \* x + c = 0*. - -6. Напишете прост калкулатор, който поддържа операциите +, -, *, / на две реални числа. - **Внимавайте с делението на 0** - -7. Да се състави програма, чрез която се въвежда 4-цифренo естествено число от интервала [1000.. 9999]. - От това число се формират 2 нови 2-цифрени числа. Първото число се формира от 1-та и 4-та цифра на въведеното - число. Второто число се формира от 2-рa - 3-та цифра на въведеното число.На екрана да се изведе дали - 1-то ново число e по-малко <, равно = или по-голямо от 2-то число. - Използвайте проверка на логическо условие - оператор if. - //Задачата е взета от [тук](http://1001zadachi.com/оператор_if_сравняване_числа.html). - - **Пример: 3332 Изход: less (32<33) - **Пример: 1144 Изход: equal (14=14) - **Пример: 9875 Изход: greater (95>87) diff --git a/pract_SI/pract. 02/task1.cpp b/pract_SI/pract. 02/task1.cpp deleted file mode 100644 index 3a60fad..0000000 --- a/pract_SI/pract. 02/task1.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -using namespace std; -int main() -{ - int year; - - cout << "Enter an year to check: "; - cin >> year; - - cout << year << " is"; - - if (!(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))) - { - cout << " not"; - } - - cout << " leap!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/task2.cpp b/pract_SI/pract. 02/task2.cpp deleted file mode 100644 index a1ddcf8..0000000 --- a/pract_SI/pract. 02/task2.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; -int main() -{ - char inputCharacter; - - cout << "Enter a character to test: "; - cin >> inputCharacter; - - cout << inputCharacter << " is "; - if (inputCharacter == 'a' || inputCharacter == 'e' || inputCharacter == 'i' || inputCharacter == 'o' || inputCharacter == 'u' || - inputCharacter == 'A' || inputCharacter == 'E' || inputCharacter == 'I' || inputCharacter == 'O' || inputCharacter == 'U') - { - cout << "a vowel!\n"; - } - else - { - if ((inputCharacter >= 'a' && inputCharacter <= 'z') || (inputCharacter >= 'A' && inputCharacter <= 'Z')) - { - cout << "a consonant!\n"; - } - else - { - cout << "is not a letter from the English alphabet!\n"; - } - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/task3 - no EPSILON.cpp b/pract_SI/pract. 02/task3 - no EPSILON.cpp deleted file mode 100644 index 6c9f832..0000000 --- a/pract_SI/pract. 02/task3 - no EPSILON.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - double x, y; - - cout << "Enter the first number: "; - cin >> x; - - cout << "Enter the second number: "; - cin >> y; - - if (fabs(x - y) < 0.000001) - { - cout << "Numbers must be different!\n"; - return 1; - } - - cout << (x < y ? y : x) << " is the greater number!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/task3 - with EPSILON.cpp b/pract_SI/pract. 02/task3 - with EPSILON.cpp deleted file mode 100644 index dcd5f88..0000000 --- a/pract_SI/pract. 02/task3 - with EPSILON.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - double num1, num2; - - cout << "Enter the first number: "; - cin >> num1; - - cout << "Enter the second number: "; - cin >> num2; - - if (fabs(num1 - num2) <= DBL_EPSILON * fabs(num1)) - { - cout << "Numbers must be different!\n"; - return 1; - } - - cout << (num1 > num2 ? "First" : "Second") << " is the greater number!\n"; - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/task4.cpp b/pract_SI/pract. 02/task4.cpp deleted file mode 100644 index acb471c..0000000 --- a/pract_SI/pract. 02/task4.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int main() -{ - double a, b, c; - - cout << "First side: "; - cin >> a; - - cout << "Second side: "; - cin >> b; - - cout << "Third side: "; - cin >> c; - - if ((a + b > c) && (a + c > b) && (b + c > a)) - { - cout << "Triangle is valid.\n"; - } - else - { - cout << "Triangle is not valid.\n"; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/task5.cpp b/pract_SI/pract. 02/task5.cpp deleted file mode 100644 index 419d6d4..0000000 --- a/pract_SI/pract. 02/task5.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - double a, b, c; - double root1, root2, imaginary; - double discriminant; - - cout << "Finding the root of the equation a * x^2 + b * x + c = 0\n"; - - cout << "Enter the value of a: "; - cin >> a; - - if (a < 0.00000001) - { - cout << "If a is 0, then this is not a quadratic equation!\n"; - return 1; - } - - cout << "Enter the value of b: "; - cin >> b; - - cout << "Enter the value of c: "; - cin >> c; - - discriminant = (b * b) - (4 * a * c); - - if (discriminant > 0) - { - root1 = (-b + sqrt(discriminant)) / (2 * a); - root2 = (-b - sqrt(discriminant)) / (2 * a); - - cout << "Two distinct and real roots exist: " << root1 << " and " << root2 << endl; - } - else if (discriminant == 0) - { - root1 = root2 = -b / (2 * a); - - cout << "Two equal and real roots exist: " << root1 << " and " << root2 << endl; - } - else if (discriminant < 0) - { - root1 = root2 = -b / (2 * a); - imaginary = sqrt(-discriminant) / (2 * a); - - cout << "Two distinct complex roots exist: " << root1 << "+" << imaginary << "i and " << root2 << "-" << imaginary << "i\n"; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/task6.cpp b/pract_SI/pract. 02/task6.cpp deleted file mode 100644 index a7484b2..0000000 --- a/pract_SI/pract. 02/task6.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -using namespace std; -int main() -{ - double a, b; - char operation; - - cout << "Enter the first number: "; - cin >> a; - - cout << "Enter the second number: "; - cin >> b; - - cout << "Choose operation: +, -, / or *: "; - cin >> operation; - - switch (operation) - { - case '+': - cout << "Result: " << a + b << endl; - break; - case '-': - cout << "Result: " << a - b << endl; - break; - case '*': - cout << "Result: " << a * b << endl; - break; - case '/': - if (b < 0.0000001) - { - cout << "You can not divide by zero!\n"; - return 1; - } - cout << "Result: " << a / b << endl; - break; - default: - cout << "Invalid operation!\n"; - break; - } - - return 0; -} \ No newline at end of file diff --git a/pract_SI/pract. 02/task7.cpp b/pract_SI/pract. 02/task7.cpp deleted file mode 100644 index 3c22a83..0000000 --- a/pract_SI/pract. 02/task7.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -using namespace std; -int main() -{ - // you can use int as well, but do you really need something as big as int? - short number; - unsigned char digit1, digit2, digit3, digit4, number1, number2; - - cout << "Enter a 4-digit number: "; - cin >> number; - - if (number < 1000 || number > 10000) - { - cout << "The input must be a 4-digit number!\n"; - return 1; - } - - digit1 = number / 1000; - digit2 = number / 100 % 10; - digit3 = number / 10 % 10; - digit4 = number % 10; - - number1 = digit1 * 10 + digit4; - number2 = digit2 * 10 + digit3; - - if (number1 < number2) - { - cout << "less (" << (int)number1 << " < " << (int)number2 << ")\n"; - } - else - { - if (number1 == number2) - { - cout << "equal (" << (int)number1 << " = " << (int)number2 << ")\n"; - } - else - { - cout << "greater (" << (int)number1 << " > " << (int)number2 << ")\n"; - } - } - - - return 0; -} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 45167f8e4f3df0ca9ad4444272c1b8acf9a08f2c Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Thu, 28 Oct 2021 17:38:59 +0300 Subject: Rename change --- pract_SI/Pract. 01/Solutions/task1.cpp | 12 ++ pract_SI/Pract. 01/Solutions/task2.cpp | 17 +++ pract_SI/Pract. 01/Solutions/task3.cpp | 16 +++ pract_SI/Pract. 01/Solutions/task4.cpp | 23 ++++ pract_SI/Pract. 01/Solutions/task5.cpp | 16 +++ pract_SI/Pract. 01/Tasks_1.txt | 20 ++++ pract_SI/Pract. 02/Solutions/task1.cpp | 20 ++++ pract_SI/Pract. 02/Solutions/task2.cpp | 29 +++++ .../Pract. 02/Solutions/task3 - no EPSILON.cpp | 23 ++++ .../Pract. 02/Solutions/task3 - with EPSILON.cpp | 24 ++++ pract_SI/Pract. 02/Solutions/task4.cpp | 26 ++++ pract_SI/Pract. 02/Solutions/task5.cpp | 51 ++++++++ pract_SI/Pract. 02/Solutions/task6.cpp | 42 +++++++ pract_SI/Pract. 02/Solutions/task7.cpp | 44 +++++++ pract_SI/Pract. 02/Tasks_2.txt | 37 ++++++ pract_SI/Pract. 03/Solutions/task1.cpp | 19 +++ pract_SI/Pract. 03/Solutions/task2.cpp | 17 +++ pract_SI/Pract. 03/Solutions/task3.cpp | 22 ++++ pract_SI/Pract. 03/Solutions/task4.cpp | 21 ++++ pract_SI/Pract. 03/Solutions/task5.cpp | 41 +++++++ pract_SI/Pract. 03/Solutions/task6.cpp | 18 +++ pract_SI/Pract. 03/Solutions/task7.cpp | 30 +++++ pract_SI/Pract. 03/Solutions/task8.cpp | 41 +++++++ pract_SI/Pract. 03/Solutions/task9.cpp | 59 ++++++++++ pract_SI/Pract. 03/Startup_tasks.txt | 7 ++ pract_SI/Pract. 03/Tasks3.txt | 131 +++++++++++++++++++++ 26 files changed, 806 insertions(+) create mode 100644 pract_SI/Pract. 01/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task2.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task3.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 01/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 01/Tasks_1.txt create mode 100644 pract_SI/Pract. 02/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task2.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task6.cpp create mode 100644 pract_SI/Pract. 02/Solutions/task7.cpp create mode 100644 pract_SI/Pract. 02/Tasks_2.txt create mode 100644 pract_SI/Pract. 03/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task2.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task3.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task6.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task7.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task8.cpp create mode 100644 pract_SI/Pract. 03/Solutions/task9.cpp create mode 100644 pract_SI/Pract. 03/Startup_tasks.txt create mode 100644 pract_SI/Pract. 03/Tasks3.txt diff --git a/pract_SI/Pract. 01/Solutions/task1.cpp b/pract_SI/Pract. 01/Solutions/task1.cpp new file mode 100644 index 0000000..54a1902 --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task1.cpp @@ -0,0 +1,12 @@ +#include +#include +using namespace std; +int main() +{ + string name; + cout << "What is your name?\n"; + cin >> name; + cout << "Hello, " << name << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task2.cpp b/pract_SI/Pract. 01/Solutions/task2.cpp new file mode 100644 index 0000000..554653d --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task2.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +int main() +{ + double x, y; + + cout << "First side: "; + cin >> x; + + cout << "Second side: "; + cin >> y; + + cout << "Parameter: " << 2 * (x + y) << endl; + cout << "Area: " << x * y << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task3.cpp b/pract_SI/Pract. 01/Solutions/task3.cpp new file mode 100644 index 0000000..830348b --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task3.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; +int main() +{ + double a, b; + + cout << "First number: "; + cin >> a; + + cout << "Second number: "; + cin >> b; + + cout << boolalpha << (a < b) << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task4.cpp b/pract_SI/Pract. 01/Solutions/task4.cpp new file mode 100644 index 0000000..b4829b4 --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task4.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace std; +int main() +{ + double x1, y1, x2, y2; + + cout << "x1: "; + cin >> x1; + + cout << "y1: "; + cin >> y1; + + cout << "x2: "; + cin >> x2; + + cout << "y2: "; + cin >> y2; + + cout << round(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) * 100) / 100 << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Solutions/task5.cpp b/pract_SI/Pract. 01/Solutions/task5.cpp new file mode 100644 index 0000000..931178d --- /dev/null +++ b/pract_SI/Pract. 01/Solutions/task5.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +using namespace std; +int main() +{ + string card_number; + + cout << "Card number: "; + cin >> card_number; + + cout << "Hidden card number: " << setfill('X') << setw(13) + << card_number[12] << card_number[13] << card_number[14] << card_number[15] << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 01/Tasks_1.txt b/pract_SI/Pract. 01/Tasks_1.txt new file mode 100644 index 0000000..bb7ee2d --- /dev/null +++ b/pract_SI/Pract. 01/Tasks_1.txt @@ -0,0 +1,20 @@ +Никола Светославов - task1 + +## Задачи +1.Напишете програма, която пита потребителя за името му, след което отпечатва "Hello, <име>" + +2.Напишете програма, която подканя потребителя да въведе дължините на двете страни на правоъгълник + **като му извежда съобщение, например "Please enter the length of the first side:"** + Програмата да изведе периметърът и лицето на този правоъгълник. + **Страните може да не са цели числа!** + +3.Напишете програма, която взима две числа от стандартния вход и извежда *true* ако първото е по - малко от второто + и *false* в противен случай. + +4.Напишете програма, която приема от входа две двойки реални числа, отговарящи на две точки в равнината. + Да се отпечата растоянието между точките закръглено до 2-рия знак след десетичната запетая. + **Потърсете математическата формула в интернет ако не я знаете!** + +БОНУС:Напишете програма която приема номер на кредитна карта(16 цифри). + Програмата да изведе същият този номер, но със скрити първите 12 цифри (XXXXXXXXXXXX1234). +БОНУС:**Направете го без да записвате X-ове променлива и без да правите ```cout<<"XXXXXXXXXXXX"``` :)** diff --git a/pract_SI/Pract. 02/Solutions/task1.cpp b/pract_SI/Pract. 02/Solutions/task1.cpp new file mode 100644 index 0000000..3a60fad --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task1.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; +int main() +{ + int year; + + cout << "Enter an year to check: "; + cin >> year; + + cout << year << " is"; + + if (!(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))) + { + cout << " not"; + } + + cout << " leap!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task2.cpp b/pract_SI/Pract. 02/Solutions/task2.cpp new file mode 100644 index 0000000..a1ddcf8 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task2.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main() +{ + char inputCharacter; + + cout << "Enter a character to test: "; + cin >> inputCharacter; + + cout << inputCharacter << " is "; + if (inputCharacter == 'a' || inputCharacter == 'e' || inputCharacter == 'i' || inputCharacter == 'o' || inputCharacter == 'u' || + inputCharacter == 'A' || inputCharacter == 'E' || inputCharacter == 'I' || inputCharacter == 'O' || inputCharacter == 'U') + { + cout << "a vowel!\n"; + } + else + { + if ((inputCharacter >= 'a' && inputCharacter <= 'z') || (inputCharacter >= 'A' && inputCharacter <= 'Z')) + { + cout << "a consonant!\n"; + } + else + { + cout << "is not a letter from the English alphabet!\n"; + } + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp new file mode 100644 index 0000000..6c9f832 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task3 - no EPSILON.cpp @@ -0,0 +1,23 @@ +#include +#include +using namespace std; +int main() +{ + double x, y; + + cout << "Enter the first number: "; + cin >> x; + + cout << "Enter the second number: "; + cin >> y; + + if (fabs(x - y) < 0.000001) + { + cout << "Numbers must be different!\n"; + return 1; + } + + cout << (x < y ? y : x) << " is the greater number!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp b/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp new file mode 100644 index 0000000..dcd5f88 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task3 - with EPSILON.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + +int main() +{ + double num1, num2; + + cout << "Enter the first number: "; + cin >> num1; + + cout << "Enter the second number: "; + cin >> num2; + + if (fabs(num1 - num2) <= DBL_EPSILON * fabs(num1)) + { + cout << "Numbers must be different!\n"; + return 1; + } + + cout << (num1 > num2 ? "First" : "Second") << " is the greater number!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task4.cpp b/pract_SI/Pract. 02/Solutions/task4.cpp new file mode 100644 index 0000000..acb471c --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task4.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() +{ + double a, b, c; + + cout << "First side: "; + cin >> a; + + cout << "Second side: "; + cin >> b; + + cout << "Third side: "; + cin >> c; + + if ((a + b > c) && (a + c > b) && (b + c > a)) + { + cout << "Triangle is valid.\n"; + } + else + { + cout << "Triangle is not valid.\n"; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task5.cpp b/pract_SI/Pract. 02/Solutions/task5.cpp new file mode 100644 index 0000000..419d6d4 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task5.cpp @@ -0,0 +1,51 @@ +#include +#include +using namespace std; +int main() +{ + double a, b, c; + double root1, root2, imaginary; + double discriminant; + + cout << "Finding the root of the equation a * x^2 + b * x + c = 0\n"; + + cout << "Enter the value of a: "; + cin >> a; + + if (a < 0.00000001) + { + cout << "If a is 0, then this is not a quadratic equation!\n"; + return 1; + } + + cout << "Enter the value of b: "; + cin >> b; + + cout << "Enter the value of c: "; + cin >> c; + + discriminant = (b * b) - (4 * a * c); + + if (discriminant > 0) + { + root1 = (-b + sqrt(discriminant)) / (2 * a); + root2 = (-b - sqrt(discriminant)) / (2 * a); + + cout << "Two distinct and real roots exist: " << root1 << " and " << root2 << endl; + } + else if (discriminant == 0) + { + root1 = root2 = -b / (2 * a); + + cout << "Two equal and real roots exist: " << root1 << " and " << root2 << endl; + } + else if (discriminant < 0) + { + root1 = root2 = -b / (2 * a); + imaginary = sqrt(-discriminant) / (2 * a); + + cout << "Two distinct complex roots exist: " << root1 << "+" << imaginary << "i and " << root2 << "-" << imaginary << "i\n"; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task6.cpp b/pract_SI/Pract. 02/Solutions/task6.cpp new file mode 100644 index 0000000..a7484b2 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task6.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; +int main() +{ + double a, b; + char operation; + + cout << "Enter the first number: "; + cin >> a; + + cout << "Enter the second number: "; + cin >> b; + + cout << "Choose operation: +, -, / or *: "; + cin >> operation; + + switch (operation) + { + case '+': + cout << "Result: " << a + b << endl; + break; + case '-': + cout << "Result: " << a - b << endl; + break; + case '*': + cout << "Result: " << a * b << endl; + break; + case '/': + if (b < 0.0000001) + { + cout << "You can not divide by zero!\n"; + return 1; + } + cout << "Result: " << a / b << endl; + break; + default: + cout << "Invalid operation!\n"; + break; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Solutions/task7.cpp b/pract_SI/Pract. 02/Solutions/task7.cpp new file mode 100644 index 0000000..3c22a83 --- /dev/null +++ b/pract_SI/Pract. 02/Solutions/task7.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; +int main() +{ + // you can use int as well, but do you really need something as big as int? + short number; + unsigned char digit1, digit2, digit3, digit4, number1, number2; + + cout << "Enter a 4-digit number: "; + cin >> number; + + if (number < 1000 || number > 10000) + { + cout << "The input must be a 4-digit number!\n"; + return 1; + } + + digit1 = number / 1000; + digit2 = number / 100 % 10; + digit3 = number / 10 % 10; + digit4 = number % 10; + + number1 = digit1 * 10 + digit4; + number2 = digit2 * 10 + digit3; + + if (number1 < number2) + { + cout << "less (" << (int)number1 << " < " << (int)number2 << ")\n"; + } + else + { + if (number1 == number2) + { + cout << "equal (" << (int)number1 << " = " << (int)number2 << ")\n"; + } + else + { + cout << "greater (" << (int)number1 << " > " << (int)number2 << ")\n"; + } + } + + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 02/Tasks_2.txt b/pract_SI/Pract. 02/Tasks_2.txt new file mode 100644 index 0000000..a419241 --- /dev/null +++ b/pract_SI/Pract. 02/Tasks_2.txt @@ -0,0 +1,37 @@ +#Никола Светославов - task2 + +## Задачи + +1. Напишете програма,която проверява дали въведена от потребителя година е високосна. + **Проверете сами кои години се считат за високосни** + +2. Напишете програма, която приема един символ от входа и проверява дали: + + * този символ е буква от латинската азбука; + * ако да, дали тази буква е гласна или съгласна. + + **Програмата да работи както за малки, така и за главни букви** + +3. Напишете програма, която приема две **различни** числа и казва кое е по голямо. + **Използвайте тернарен оператор** + +4. Напишете програма, която приема от входа три числа - страни на триъгълник. + Програмата да проверява дали това е валиден триъгълник. + +5. Напишете програма, която намира корените на квадратно уравнение. + За целта потребителя да въведе коефицентите на уравнението - *a*, *b*, и *c* + при уравнение с вид *a \* x^2 + b \* x + c = 0*. + +6. Напишете прост калкулатор, който поддържа операциите +, -, *, / на две реални числа. + **Внимавайте с делението на 0** + +7. Да се състави програма, чрез която се въвежда 4-цифренo естествено число от интервала [1000.. 9999]. + От това число се формират 2 нови 2-цифрени числа. Първото число се формира от 1-та и 4-та цифра на въведеното + число. Второто число се формира от 2-рa - 3-та цифра на въведеното число.На екрана да се изведе дали + 1-то ново число e по-малко <, равно = или по-голямо от 2-то число. + Използвайте проверка на логическо условие - оператор if. + //Задачата е взета от [тук](http://1001zadachi.com/оператор_if_сравняване_числа.html). + + **Пример: 3332 Изход: less (32<33) + **Пример: 1144 Изход: equal (14=14) + **Пример: 9875 Изход: greater (95>87) diff --git a/pract_SI/Pract. 03/Solutions/task1.cpp b/pract_SI/Pract. 03/Solutions/task1.cpp new file mode 100644 index 0000000..ae955a8 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task1.cpp @@ -0,0 +1,19 @@ +#include "pch.h" +#include + +using namespace std; + +int main() +{ + unsigned long long number; + cin >> number; + + for (int i = 1; i <= number; i++) + { + for (int j = 1; j <= i; j++) + cout << j; + cout << endl; + } + + return 0; +} diff --git a/pract_SI/Pract. 03/Solutions/task2.cpp b/pract_SI/Pract. 03/Solutions/task2.cpp new file mode 100644 index 0000000..b3e970d --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task2.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +int main() +{ + unsigned long long number; + cin >> number; + + for (unsigned long long x = 1, y = number; x < number; x++) + { + cout << "x = " << x << " " + << "y = " << --y << endl; + } + + return 0; +} diff --git a/pract_SI/Pract. 03/Solutions/task3.cpp b/pract_SI/Pract. 03/Solutions/task3.cpp new file mode 100644 index 0000000..a6a6362 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task3.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; +int main() +{ + unsigned long long oldNumber, newNumber; + + cout << "Enter a positive number: "; + cin >> oldNumber; + + oldNumber *= oldNumber; + newNumber = 0; + + while (oldNumber != 0) + { + newNumber = newNumber * 10 + oldNumber % 10; + oldNumber /= 10; + } + + cout << newNumber << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task4.cpp b/pract_SI/Pract. 03/Solutions/task4.cpp new file mode 100644 index 0000000..622b8a1 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task4.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +int main() +{ + unsigned int m, n; + cout << "Number of rows: "; + cin >> m; + cout << "Number of columns: "; + cin >> n; + + for (unsigned int i = 1; i <= m * n; i++) + { + cout << i << " "; + if (i % n == 0) + { + cout << endl; + } + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task5.cpp b/pract_SI/Pract. 03/Solutions/task5.cpp new file mode 100644 index 0000000..d6ac57c --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task5.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +int main() +{ + unsigned short number, guess; + unsigned int counter = 0; + + cout << "Enter a number between 0 and 100: "; + cin >> number; + if (number < 0 || number > 100) + { + cout << "Invalid input!\n"; + return 1; + } + + do + { + ++counter; + + cout << "Guess " << counter << ": "; + cin >> guess; + if (guess < 0 || guess > 100) + { + cout << "Invalid input!\n"; + return 2; + } + + if (guess < number) + { + cout << "The number you are looking for is greater than your guess!\n"; + } + else if (guess > number) + { + cout << "The number you are looking for is less than your guess!\n"; + } + } while (guess != number); + + cout << "You found the number in " << counter << " attempt(s)!\n"; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task6.cpp b/pract_SI/Pract. 03/Solutions/task6.cpp new file mode 100644 index 0000000..8d0beac --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task6.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +int main() +{ + unsigned int number = 0, input = 1; + + while(input != 0) + { + cout << "Enter a positive number: "; + cin >> input; + + number ^= input; + } + + cout << "The single number is " << number << endl; + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task7.cpp b/pract_SI/Pract. 03/Solutions/task7.cpp new file mode 100644 index 0000000..aa9194b --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task7.cpp @@ -0,0 +1,30 @@ +#include +#define LIMIT 5 +#define SEPARATOR " " + +using namespace std; + +//const short LIMIT = 5; +//const char SEPARATOR = ' '; + + +int main() +{ + unsigned long long N; + cin >> N; + + if (N < LIMIT) + return -1; + + for (int c = 1; c <= N; c++) { + for (int b = 1; b < c; b++) { + for (int a = 1; a < b; a++) { + if ((a * a) + (b * b) == (c * c)) { + cout << a << SEPARATOR << b << SEPARATOR << c << endl; + } + } + } + } + + return 0; +} diff --git a/pract_SI/Pract. 03/Solutions/task8.cpp b/pract_SI/Pract. 03/Solutions/task8.cpp new file mode 100644 index 0000000..3f32ebf --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task8.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +const short LOWERLIMIT = 2; +const short UPPERLIMIT = 9; +const char SEPARATOR = ' '; + +int main() +{ + short N; + char S; + cin >> N >> S; + + if (N < LOWERLIMIT || N > UPPERLIMIT) + return -1; //end program + + for (int i = 1; i <= N; i++) + { + for (int j = N - i; j > 0; j--) + cout << SEPARATOR; + + for (int k = 1; k < 2 * i; k++) + cout << S; + + cout << endl; + } + + for (int i = 1; i < N; i++) + { + for (int j = 1; j <= i; j++) + cout << SEPARATOR; + + for (int k = 1; k < 2 * (N - i); k++) + cout << S; + + cout << endl; + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Solutions/task9.cpp b/pract_SI/Pract. 03/Solutions/task9.cpp new file mode 100644 index 0000000..9f1f054 --- /dev/null +++ b/pract_SI/Pract. 03/Solutions/task9.cpp @@ -0,0 +1,59 @@ +#include + +int main() { + + // по-нататък ще учим как се вкарват сложни данни, затова сега ще ги hardcode-нем в main-а + + int hoursOnesStart = 2, minutesTensStart = 5, secondsOnesStart = 6; + int hoursOnesFinal = 1, minutesTensFinal = 0, secondsOnesFinal = 2; + int hoursDelta = 10, minutesDelta = 19, secondsDelta = 26; + + for (size_t hoursTensStart = 0; hoursTensStart <= 1; ++hoursTensStart) + { + for (size_t minutesOnesStart = 0; minutesOnesStart <= 9; ++minutesOnesStart) + { + for (size_t secondsTensStart = 0; secondsTensStart <= 5; secondsTensStart++) + { + int hoursTemp = hoursTensStart * 10 + hoursOnesStart; + int minutesTemp = minutesTensStart * 10 + minutesOnesStart; + int secondsTemp = secondsTensStart * 10 + secondsOnesStart; + + secondsTemp += secondsDelta; + if (secondsTemp >= 60) { + minutesTemp += secondsTemp / 60; + secondsTemp %= 60; + } + + minutesTemp += minutesDelta; + if (minutesTemp >= 60) { + hoursTemp += minutesTemp / 60; + minutesTemp %= 60; + } + + hoursTemp += hoursDelta; + if (hoursTemp > 12) { + hoursTemp %= 12; + } + + bool hoursOnesMatch = hoursTemp % 10 == hoursOnesFinal, + minutesTensMatch = minutesTemp / 10 == minutesTensFinal, + secondsOnesMatch = secondsTemp % 10 == secondsOnesFinal; + + if (hoursOnesMatch && minutesTensMatch && secondsOnesMatch) { + int hoursTensFinal = hoursTemp / 10, + minutesOnesFinal = minutesTemp % 10, + secondsTensFinal = secondsTemp / 10; + + std::cout << hoursTensStart << hoursOnesStart << ':' + << minutesTensStart << minutesOnesStart << ':' + << secondsTensStart << secondsOnesStart << ' ' + << hoursTensFinal << hoursOnesFinal << ':' + << minutesTensFinal << minutesOnesFinal << ':' + << secondsTensFinal << secondsOnesFinal << '\n'; + } + } + } + } + + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Startup_tasks.txt b/pract_SI/Pract. 03/Startup_tasks.txt new file mode 100644 index 0000000..8ee6d58 --- /dev/null +++ b/pract_SI/Pract. 03/Startup_tasks.txt @@ -0,0 +1,7 @@ +1.Напишете програма , която приема като вход N лева.Да се отпечата как бихме разпределили сумата на банкноти, +така че да имаме минимален брой банкноти. (Да не се използват условни оператори и цикли) +Пояснение: Нека да приемем, че имаме банкноти с 1лв и 2лв. + +2.Напишете програма, която приема като вход цяло положително число V, което ще отговаря на скорост. +Програмата да отпечатва колко е глобата от КАТ, а ако няма глоба следното съобщение "No speedticket". +(https://stamatovandpartners.com/elektronen-fish-za-previshena-skorost/) \ No newline at end of file diff --git a/pract_SI/Pract. 03/Tasks3.txt b/pract_SI/Pract. 03/Tasks3.txt new file mode 100644 index 0000000..64c5c4c --- /dev/null +++ b/pract_SI/Pract. 03/Tasks3.txt @@ -0,0 +1,131 @@ +#Никола Светославов - task3 + +## Задачи + +1.Да се напише програма, която приема естествено число n и изписва стълба от 1 до n + +Пример +Вход: +5 +Изход: +1 +12 +123 +1234 +12345 + +2.Да се състави програма, която по въведено естествено число n да изведе всички естествени решения на уравнението x + y = n. + +Пример +Вход: +4 +Изход: +x = 1 y = 3 +x = 2 y = 2 +x = 3 y = 1 + + +3.Напишете програма, която по въведено цяло положително число, извежда квадратът на това число, но в обратен ред, като водещите нули се игнорират. + +Пример +Вход: +10 +Изход: +1 + +Вход: +25 +Изход: +526 + +4.Напишете програма, която приема от потребителя две цели положителни числа - *m* и *n*. + Програмата да отпечата числатаот 1 до m*n, като на всеки ред има по *n* числа (тоест ще отпечатате *m* реда). + Печатайте числата по редове: + +Пример +Вход: +2 3 +Изход: +1 2 3 +4 5 6 + +5.Напишете проста игра, в която първо се въвежда цяло число в интервала [0;100] и в последствие се въвеждат цели числа + (предположения), като за всяко се казва дали е по - малко или по - голямо от първоначално ваведеното. + Tова продължава до въвеждане на число, равно на първоначалното. Програмата да отпечата и броят направени предположения. + +6.Напишете програма, която иска от потребителя поредица от цели числа по - големи от 0. + Въвеждането приключва с въвеждане на 0. Гарантирано е, че всяко от числата е въведено **точно два пъти** освен едно, + което е въведено **точно веднъж**. Програмата да изведе кое е това число. + +7.Да се състави програма, която по въведено естествено число N намира и отпечатва всички тройки естествени числа a, b и c, + не по-големи от N, които могат да бъдат страни на правоъгълен триъгълник. + +Пример +Вход: +11 +Изход +3 4 5 +6 8 10 + +8.Напишете програма, която иска от потребителя вход цифра N[2;9] и символ S.Програмата да извежда фигура съставена от символа във вид на ромб, както е показано на примерите. + +Пример +Вход: +5 * +Изход + * + *** + ***** + ******* +********* + ******* + ***** + *** + * + +*Бонус* +Задача ЕЛЕКТРОНЕН ЧАСОВНИК +В големия нов МОЛ в града на програмистите се повредили част от цифрите на електронния часовник. +Повредени били първата цифра от числото, което показва часовете, втората цифра на числото, което показва минутите и първата цифра на числото, което показва секундите. +Вместо тях на екрана се появявал знака *. +Когато Коко и приятелите му ходели на кино, те не успявали да преценят точно колко е часа. +Все пак, момчетата си създали система за изчисление, която приблизително точно им показвало времето. +Те успявали да предвидят колко е показвал часовника в началото и края на филма, в случай че знаят точно колко време е минало. +Срещу името на всеки филм на входа на киното е дадено неговото времетраене в часове, минути и секунди. +Пресмятанията доста затрудняват момчетата и затова на тях ще им е по-удобно това да се прави с компютърна програма. +Те не разбират много от програмиране и затова вие трябва да напишете програма clock, която помага на Коко и приятелите му. + +Вход: +На първия ред на стандартния вход е записана последователност от цифри и знака *, която показва какво се вижда на екрана на часовника в началото на филма. +На втория ред е записана подобна последователност за показанието на часовника в края на филма. +На третия ред се въвежда продължителността на филма в часове, минути и секунди. +Часовникът е настроен така, че показва времето по 12-часова скала, а не по 24-часова. + +Изход: +На стандартния изход изведете всички възможни показания на часовника за началото и края на филма. +Всяка двойка с начален и краен час се извежда на един ред, като първо се извежда началното показание във формат hh:mm:ss, и след един интервал крайното показание в същия формат. +Ако такива показания на часовника не са възможни, да се изведе “Impossible”. + +Ограничения: +Продължителността на филма е не по-голяма 12 часа. + +Примери: + +Вход: +*25**6 +*10**2 +10 19 26 +Изход: +02:50:06 01:09:32 +02:50:16 01:09:42 +02:50:26 01:09:52 +12:50:06 11:09:32 +12:50:16 11:09:42 +12:50:26 11:09:52 + +Вход: +*95**6 +*21**2 +4 12 6 +Изход: +Impossible -- cgit v1.3.1-23-gd82d From a78a314b374e5372c3865f16bde40845db5b79a2 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:51:13 -0400 Subject: Create exercise 10.cpp --- Sem. 03/solutions/exercise 10.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Sem. 03/solutions/exercise 10.cpp diff --git a/Sem. 03/solutions/exercise 10.cpp b/Sem. 03/solutions/exercise 10.cpp new file mode 100644 index 0000000..dae43ab --- /dev/null +++ b/Sem. 03/solutions/exercise 10.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + for (int j = 0; j < count; j++) + { + if (j % 2 == 0) + { + cout << i + (count * j) << " "; + } + else + { + cout << (j + 1) * count - (i - 1) << " "; + } + } + cout << endl; + } +} -- cgit v1.3.1-23-gd82d From 235bbe2ccc3565f8af02f9cddd76b8937f6dff33 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:51:25 -0400 Subject: Rename exercise 8 - dollar pyramid.cpp to exercise 08 - dollar pyramid.cpp --- Sem. 03/solutions/exercise 08 - dollar pyramid.cpp | 19 +++++++++++++++++++ Sem. 03/solutions/exercise 8 - dollar pyramid.cpp | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 Sem. 03/solutions/exercise 08 - dollar pyramid.cpp delete mode 100644 Sem. 03/solutions/exercise 8 - dollar pyramid.cpp diff --git a/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp new file mode 100644 index 0000000..1ea164d --- /dev/null +++ b/Sem. 03/solutions/exercise 08 - dollar pyramid.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + + int n; + cin >> n; + + for(int i = 1; i <= n; i++) + { + for(int j = 1; j <= i; j++) + cout << "$" << " "; // print as many dollars as the number of the current row + + cout << endl; + } + + return 0; +} diff --git a/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp b/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp deleted file mode 100644 index 65f6106..0000000 --- a/Sem. 03/solutions/exercise 8 - dollar pyramid.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -using namespace std; - -int main() -{ - - int n; - cin >> n; - - for(int i = 1; i <= n; i++) - { - for(int j = 1; j <= i; j++) - cout << "$" << " "; // print as many dollars as the number of the current row - - cout << endl; - } - - return 0; -} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 4eb49067c08480fa0b435e6969655e142b71600d Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:51:36 -0400 Subject: Rename exercise 9 - rightmost pyramid.cpp to exercise 09 - rightmost pyramid.cpp --- .../solutions/exercise 09 - rightmost pyramid.cpp | 36 ++++++++++++++++++++++ .../solutions/exercise 9 - rightmost pyramid.cpp | 36 ---------------------- 2 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp delete mode 100644 Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp diff --git a/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp new file mode 100644 index 0000000..573b98b --- /dev/null +++ b/Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +int main() +{ + + int n; + cin >> n; + + // print the first part of the pyramid (the one going from 1 to n(n-1)...21) + + for(int i = 1; i <= n; i++) + { + for(int k = n - i - 1; k >= 0; k--) + cout << " "; // print the spaces + + for(int j = i; j >= 1; j--) + cout << j; // print numbers j(j - 1)...21 + + cout << endl; + } + // print the second part of the pyramid (the one going from (n-1)...21 to 1 + + for(int i = n - 1; i >= 1; i--) + { + for(int k = n - i - 1; k >= 0; k--) + cout << " "; + + for(int j = i; j >= 1; j--) + cout << j; + + cout << endl; + } + + return 0; +} diff --git a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp b/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp deleted file mode 100644 index d1b339a..0000000 --- a/Sem. 03/solutions/exercise 9 - rightmost pyramid.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -using namespace std; - -int main() -{ - - int n; - cin >> n; - - // print the first part of the pyramid (the one going from 1 to n(n-1)...21) - - for(int i = 1; i <= n; i++) - { - for(int k = n - i - 1; k >= 0; k--) - cout << " "; // print the spaces - - for(int j = i; j >= 1; j--) - cout << j; // print numbers j(j - 1)...21 - - cout << endl; - } - // print the second part of the pyramid (the one going from (n-1)...21 to 1 - - for(int i = n - 1; i >= 1; i--) - { - for(int k = n - i - 1; k >= 0; k--) - cout << " "; - - for(int j = i; j >= 1; j--) - cout << j; - - cout << endl; - } - - return 0; -} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 4e4a0a5458c2e9b015d37956f10fe67f00c05285 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:51:58 -0400 Subject: Delete example 11 - reverse numbers by row --- Sem. 03/example 11 - reverse numbers by row | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 Sem. 03/example 11 - reverse numbers by row diff --git a/Sem. 03/example 11 - reverse numbers by row b/Sem. 03/example 11 - reverse numbers by row deleted file mode 100644 index 66a90a9..0000000 --- a/Sem. 03/example 11 - reverse numbers by row +++ /dev/null @@ -1,28 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int count; - cin >> count; - - for (int i = 1; i <= count; i++) - { - if (i % 2 != 0) - { - for (int j = 1 + ((i - 1) * count); j <= i * count; j++) - { - cout << j << " "; - } - } - else - { - for (int j = i * count; j > (i - 1) * count; j--) - { - cout << j << " "; - } - } - cout << endl; - } -} -- cgit v1.3.1-23-gd82d From c132894e81e29e4c6c6dfa3a2ea70aea95860955 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:52:11 -0400 Subject: Create exercise 11.cpp --- Sem. 03/solutions/exercise 11.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Sem. 03/solutions/exercise 11.cpp diff --git a/Sem. 03/solutions/exercise 11.cpp b/Sem. 03/solutions/exercise 11.cpp new file mode 100644 index 0000000..66a90a9 --- /dev/null +++ b/Sem. 03/solutions/exercise 11.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main() +{ + int count; + cin >> count; + + for (int i = 1; i <= count; i++) + { + if (i % 2 != 0) + { + for (int j = 1 + ((i - 1) * count); j <= i * count; j++) + { + cout << j << " "; + } + } + else + { + for (int j = i * count; j > (i - 1) * count; j--) + { + cout << j << " "; + } + } + cout << endl; + } +} -- cgit v1.3.1-23-gd82d From 074da16fc9c98cf99a350939b51ec69c9b201801 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Thu, 28 Oct 2021 10:55:06 -0400 Subject: Delete example 10 - matrix --- Sem. 03/example 10 - matrix | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 Sem. 03/example 10 - matrix diff --git a/Sem. 03/example 10 - matrix b/Sem. 03/example 10 - matrix deleted file mode 100644 index dae43ab..0000000 --- a/Sem. 03/example 10 - matrix +++ /dev/null @@ -1,25 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int count; - cin >> count; - - for (int i = 1; i <= count; i++) - { - for (int j = 0; j < count; j++) - { - if (j % 2 == 0) - { - cout << i + (count * j) << " "; - } - else - { - cout << (j + 1) * count - (i - 1) << " "; - } - } - cout << endl; - } -} -- cgit v1.3.1-23-gd82d From a6e73ce736a7c0e7decb30c9ee63eeca3d14e735 Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Thu, 28 Oct 2021 18:11:24 +0300 Subject: Added Startup_tasks solutions --- .../Startup_tasks - Solutions/task1_solution1.cpp | 35 +++++++++++++++++++++ .../Startup_tasks - Solutions/task1_solution2.cpp | 35 +++++++++++++++++++++ .../Pract. 03/Startup_tasks - Solutions/task2.cpp | 36 ++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution1.cpp create mode 100644 pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution2.cpp create mode 100644 pract_SI/Pract. 03/Startup_tasks - Solutions/task2.cpp diff --git a/pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution1.cpp b/pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution1.cpp new file mode 100644 index 0000000..988d53c --- /dev/null +++ b/pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution1.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +int main() +{ + int n, initialSum; + cin >> n; + initialSum = n; + + int Hundred_Dollar_Bill = 0; + int Fifty_Dollar_Bill = 0; + int Twenty_Dollar_Bill = 0; + int Ten_Dollar_Bill = 0; + int Five_Dollar_Bill = 0; + int Two_Dollar_Bill = 0; + int One_Dollar_Bill = 0; + + Hundred_Dollar_Bill = n / 100; + n %= 100; + Fifty_Dollar_Bill = n / 50; + n %= 50; + Twenty_Dollar_Bill = n / 20; + n %= 20; + Ten_Dollar_Bill = n / 10; + n %= 10; + Five_Dollar_Bill = n / 5; + n %= 5; + Two_Dollar_Bill = n / 2; + n %= 2; + One_Dollar_Bill = n; + + cout << initialSum << " = " << Hundred_Dollar_Bill << "*100 + " << Fifty_Dollar_Bill << "*50 + " << Twenty_Dollar_Bill << "*20 + " << Ten_Dollar_Bill << "*10 + " << + Five_Dollar_Bill << "*5 + " << Two_Dollar_Bill << "*2 + " << One_Dollar_Bill << "*1" << endl; +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution2.cpp b/pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution2.cpp new file mode 100644 index 0000000..f01ec74 --- /dev/null +++ b/pract_SI/Pract. 03/Startup_tasks - Solutions/task1_solution2.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +int main() +{ + unsigned long long money; //assign money's interval + cin >> money; //enter number of money + + cout << "Initial price: " << money << " = "; //Initial price output + + cout << money / 100 << "*100 + "; //output for 100 + money %= 100; //reduce the 100's + + cout << money / 50 << "*50 + "; //output for 50 + money %= 50; //reduce the 50's + + cout << money / 20 << "*20 + "; //output for 20 + money %= 20; //reduce the 20's + + cout << money / 10 << "*10 + "; //output for 10 + money %= 10; //reduce the 10's + + cout << money / 5 << "*5 + "; //output for 5 + money %= 5; //reduce the 5's + + cout << money / 2 << "*2 + "; //output for 2 + money %= 2; //reduce the 2's + + cout << money / 1 << "*1" << endl; //output for 1 + money %= 1; //reduce the 1's + + cout << "End of program" << endl; //end program + return 0; //end program +} \ No newline at end of file diff --git a/pract_SI/Pract. 03/Startup_tasks - Solutions/task2.cpp b/pract_SI/Pract. 03/Startup_tasks - Solutions/task2.cpp new file mode 100644 index 0000000..ab5ca6f --- /dev/null +++ b/pract_SI/Pract. 03/Startup_tasks - Solutions/task2.cpp @@ -0,0 +1,36 @@ +#include + +using namespace std; + +int main() +{ + unsigned long long velocity; //assign velocity's interval + cin >> velocity; //enter velocity's value + + if (velocity < 10) + cout << "No fine" << endl; + else if (velocity == 10) + cout << "Fine: 20$" << endl; + else if (velocity < 20) + cout << "Fine: 50$" << endl; + else if (velocity < 30) + cout << "Fine: 100$" << endl; + else if (velocity < 40) + cout << "Fine if in Urban area: 400$" << endl //Urban area fine + << "Fine if in Metropolitan area: 300$" << endl; //Metropolitan area fine + else if(velocity <= 50) + cout << "Fine if in Urban area: 600$" << endl //Urban area fine + << "Fine if in Metropolitan area: 400$" << endl;//Metropolitan area fine + else + { + unsigned long long fine = 700 + (((velocity - 50) / 5) * 50); + + + cout << "Fine if in Urban area: " << fine << "$" << endl + << "Additional 3 months driver licence suspension and 12 driver control points." << endl << endl; //Urban area fine + cout << "Fine if in Metropolitan area: " << fine - 100 << "$" << endl;//Metropolitan area fine + } + + cout << endl << "End of program" << endl; //end program + return 0; //end program +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From d9639a5a2b4e3b732738f8021e90d62e34279020 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Fri, 29 Oct 2021 01:14:44 +0300 Subject: Update README.md --- Sem. 03/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 03/README.md b/Sem. 03/README.md index af93bf2..dae7155 100644 --- a/Sem. 03/README.md +++ b/Sem. 03/README.md @@ -71,7 +71,7 @@ do *Вход: 60 30 Изход: 30 15 10 6 5 3 2 1* -*Вход: 5 4 3 0 Изход: 12* +*Вход: 19 17 Изход: 1* **Задача 3:** Да се напише програма, която приема число и премахва среднaта цифра , ако числото има нечетен брой цифри или премахва средните две цифри, ако числото има четен брой цифри. След това да се отпечата числото увеличено с 1-ца. -- cgit v1.3.1-23-gd82d -- cgit v1.3.1-23-gd82d From c7a3d4073cfc39775cb99254cf263ed295bea7f3 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Sat, 30 Oct 2021 06:38:22 -0400 Subject: Create tasks.cpp --- Sem. 04_KN/tasks.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 Sem. 04_KN/tasks.cpp diff --git a/Sem. 04_KN/tasks.cpp b/Sem. 04_KN/tasks.cpp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Sem. 04_KN/tasks.cpp @@ -0,0 +1 @@ + -- cgit v1.3.1-23-gd82d From 923e814a80dfbcb177509392c526869e406f8bc6 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Sat, 30 Oct 2021 13:42:27 +0300 Subject: Create tasks.cpp --- Sem. 04_KN/tasks.cpp | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) diff --git a/Sem. 04_KN/tasks.cpp b/Sem. 04_KN/tasks.cpp index 8b13789..1b073bf 100644 --- a/Sem. 04_KN/tasks.cpp +++ b/Sem. 04_KN/tasks.cpp @@ -1 +1,229 @@ +#include +using namespace std; + +/* +<параметри> = <тип> <име> +<тип на връщане> <идентификатор> (<параметри>) +{ + // тяло на функцията/ + + //return - какво връща функцията в този случай. +} + +*/ + + +//задача 1: +// Въвежда се цяло число n. +// Да се отпечатат всички двойки прости числа, които са +// във вида 6k-1 и 6k+1 и са по по-малки от n. + +// n = 50 +// 5 7 +// 11 13 +// 17 19 +// 41 43 + +bool isPrime(int n) +{ + double temp = sqrt(n); + + if (n < 2) + return false; + + for (int i = 2; i <= temp; i++) + { + if (n % i == 0) + return false; + } + return true; +} + + + +//задача 2: +// Напишете функция, която приема число и връща обърнатото. +// Вход: 1234 Изход: 4321 + +int reverse(int n) +{ + int result = 0; + while (n != 0) + { + int lastDigit = n % 10; + (result *= 10) += lastDigit; // result = (result = result * 10) + lastDigit + n /= 10; + } + return result; +} + +//задача 3: +// Напишете функция, която приема число и връща дали е палиндром. +// Вход: 121 Изход: true +// Вход: 1213 Изход: false +bool isPalindrome(int n) +{ + return reverse(n) == n; +} + +//задача 4: Напишете функция, която приема две цели числа - n и k. +// и връща дали k е суфикс на n. + +// n = 1234 +// k = 34 true + +// n = 1234 +// k = 23 false + +bool isSuffix(unsigned n, unsigned k) +{ + if (n < k) + return false; + + while (k != 0) + { + int nLastDigit = n % 10; + int kLastDigit = k % 10; + + if (nLastDigit != kLastDigit) + return false; + + n /= 10; + k /= 10; + } + + return true; +} +// w is pref u <-> w^rev is suff u^rev + +//задача 5: Напишете функция, която приема две цели числа (n, k) +//и връща дали k е префикс на n. +bool isPrefix(unsigned n, unsigned k) +{ + return isSuffix(reverse(n), reverse(k)); +} + +//задача 6: Напишете функция, която приема две цели числа (n,k) +// и връща дали k е инфикс на n. +bool isInfix(unsigned n, unsigned k) +{ + while (n > k) + { + if (isSuffix(n, k)) + return true; + n /= 10; + } + return false; +} + +// задача 7: Напишете функция, която приема цяло число и връща +// дали цифрите му са сортирани. + +// -> възходящо +// -> низходящо +bool areDigitsSortedIncreasing(unsigned n) +{ + cout << "areDigitsSortedIncreasing" << endl; + while (n >= 10) + { + int lastDigit = n % 10; + int prevLastDigit = (n / 10) % 10; + + if (prevLastDigit > lastDigit) + return false; + + n /= 10; + } + return true; +} + +bool areDigitsSortedDecreasing(unsigned n) +{ + cout << "areDigitsSortedDecreasing" << endl; + return areDigitsSortedIncreasing(reverse(n)); +} + +bool areDigitsSorted(int n) +{ + return areDigitsSortedIncreasing(n) || areDigitsSortedDecreasing(n); +} + +//задача 8: Въвежда се цяло число. Отпечатайте дали се състои от еднакви цифри +// 111111 - труе +// 123432 - фалсе + +bool areDigitsTheSame(int n) +{ + return areDigitsSortedIncreasing(n) && areDigitsSortedDecreasing(n); +} + +void print(int n) +{ + cout << n << endl; + + return; //функцията да приключи + + //code - кодът е недостижим +} + +int main() +{ + int n; + cin >> n; + + + //task1 + // GOOD + + //for (int i = 6; i < n; i += 6) + //{ + // if (isPrime(i - 1) && isPrime(i + 1)) + // cout << i - 1 << " " << i + 1 << endl; + //} + + + + + //task1 + //BAD + + + //for (int i = 6; i < n; i += 6) + //{ + // int firstToCheck = i - 1; + // int secondToCheck = i + 1; + + // //primality check for the first + + // bool isFirstPrime = true; + // double sqrtFirst = sqrt(firstToCheck); + // for (int j = 2; j <= sqrtFirst; j++) + // { + // if (firstToCheck % j == 0) + // { + // isFirstPrime = false; + // break; + // } + // } + // if (!isFirstPrime) + // continue; + + + // //primality check for the second + + // bool isSecondPrime = true; + // double sqrtSecond = sqrt(secondToCheck); + // for (int j = 2; j <= sqrtSecond; j++) + // { + // if (secondToCheck % j == 0) + // { + // isSecondPrime = false; + // break; + // } + // } + + // if (isSecondPrime) + // cout << firstToCheck << " " << secondToCheck << endl; + //} +} -- cgit v1.3.1-23-gd82d From 69a96e3366764c716af5a9cd5bb543215bb6d920 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Mon, 1 Nov 2021 13:59:37 +0200 Subject: Update tasks.cpp --- Sem. 04_KN/tasks.cpp | 230 +-------------------------------------------------- 1 file changed, 1 insertion(+), 229 deletions(-) diff --git a/Sem. 04_KN/tasks.cpp b/Sem. 04_KN/tasks.cpp index 1b073bf..9c558e3 100644 --- a/Sem. 04_KN/tasks.cpp +++ b/Sem. 04_KN/tasks.cpp @@ -1,229 +1 @@ - -#include -using namespace std; - -/* -<параметри> = <тип> <име> -<тип на връщане> <идентификатор> (<параметри>) -{ - // тяло на функцията/ - - //return - какво връща функцията в този случай. -} - -*/ - - -//задача 1: -// Въвежда се цяло число n. -// Да се отпечатат всички двойки прости числа, които са -// във вида 6k-1 и 6k+1 и са по по-малки от n. - -// n = 50 -// 5 7 -// 11 13 -// 17 19 -// 41 43 - -bool isPrime(int n) -{ - double temp = sqrt(n); - - if (n < 2) - return false; - - for (int i = 2; i <= temp; i++) - { - if (n % i == 0) - return false; - } - return true; -} - - - -//задача 2: -// Напишете функция, която приема число и връща обърнатото. -// Вход: 1234 Изход: 4321 - -int reverse(int n) -{ - int result = 0; - while (n != 0) - { - int lastDigit = n % 10; - (result *= 10) += lastDigit; // result = (result = result * 10) + lastDigit - n /= 10; - } - return result; -} - -//задача 3: -// Напишете функция, която приема число и връща дали е палиндром. -// Вход: 121 Изход: true -// Вход: 1213 Изход: false -bool isPalindrome(int n) -{ - return reverse(n) == n; -} - -//задача 4: Напишете функция, която приема две цели числа - n и k. -// и връща дали k е суфикс на n. - -// n = 1234 -// k = 34 true - -// n = 1234 -// k = 23 false - -bool isSuffix(unsigned n, unsigned k) -{ - if (n < k) - return false; - - while (k != 0) - { - int nLastDigit = n % 10; - int kLastDigit = k % 10; - - if (nLastDigit != kLastDigit) - return false; - - n /= 10; - k /= 10; - } - - return true; -} -// w is pref u <-> w^rev is suff u^rev - -//задача 5: Напишете функция, която приема две цели числа (n, k) -//и връща дали k е префикс на n. -bool isPrefix(unsigned n, unsigned k) -{ - return isSuffix(reverse(n), reverse(k)); -} - -//задача 6: Напишете функция, която приема две цели числа (n,k) -// и връща дали k е инфикс на n. -bool isInfix(unsigned n, unsigned k) -{ - while (n > k) - { - if (isSuffix(n, k)) - return true; - n /= 10; - } - return false; -} - -// задача 7: Напишете функция, която приема цяло число и връща -// дали цифрите му са сортирани. - -// -> възходящо -// -> низходящо -bool areDigitsSortedIncreasing(unsigned n) -{ - cout << "areDigitsSortedIncreasing" << endl; - while (n >= 10) - { - int lastDigit = n % 10; - int prevLastDigit = (n / 10) % 10; - - if (prevLastDigit > lastDigit) - return false; - - n /= 10; - } - return true; -} - -bool areDigitsSortedDecreasing(unsigned n) -{ - cout << "areDigitsSortedDecreasing" << endl; - return areDigitsSortedIncreasing(reverse(n)); -} - -bool areDigitsSorted(int n) -{ - return areDigitsSortedIncreasing(n) || areDigitsSortedDecreasing(n); -} - -//задача 8: Въвежда се цяло число. Отпечатайте дали се състои от еднакви цифри -// 111111 - труе -// 123432 - фалсе - -bool areDigitsTheSame(int n) -{ - return areDigitsSortedIncreasing(n) && areDigitsSortedDecreasing(n); -} - -void print(int n) -{ - cout << n << endl; - - return; //функцията да приключи - - //code - кодът е недостижим -} - -int main() -{ - int n; - cin >> n; - - - //task1 - // GOOD - - //for (int i = 6; i < n; i += 6) - //{ - // if (isPrime(i - 1) && isPrime(i + 1)) - // cout << i - 1 << " " << i + 1 << endl; - //} - - - - - //task1 - //BAD - - - //for (int i = 6; i < n; i += 6) - //{ - // int firstToCheck = i - 1; - // int secondToCheck = i + 1; - - // //primality check for the first - - // bool isFirstPrime = true; - // double sqrtFirst = sqrt(firstToCheck); - // for (int j = 2; j <= sqrtFirst; j++) - // { - // if (firstToCheck % j == 0) - // { - // isFirstPrime = false; - // break; - // } - // } - // if (!isFirstPrime) - // continue; - - - // //primality check for the second - - // bool isSecondPrime = true; - // double sqrtSecond = sqrt(secondToCheck); - // for (int j = 2; j <= sqrtSecond; j++) - // { - // if (secondToCheck % j == 0) - // { - // isSecondPrime = false; - // break; - // } - // } - - // if (isSecondPrime) - // cout << firstToCheck << " " << secondToCheck << endl; - //} -} +. -- cgit v1.3.1-23-gd82d From 76d522c2b556c3d2d3f1c3f199ae611272e49b83 Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Mon, 1 Nov 2021 15:47:22 +0200 Subject: Added Pract. 04 Tasks --- pract_SI/Pract. 04/Task4.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pract_SI/Pract. 04/Task4.txt diff --git a/pract_SI/Pract. 04/Task4.txt b/pract_SI/Pract. 04/Task4.txt new file mode 100644 index 0000000..cc5f735 --- /dev/null +++ b/pract_SI/Pract. 04/Task4.txt @@ -0,0 +1,32 @@ +#Никола Светославов - task4 + +## Задачи + +1. Да се състави функция sum(const int a, const int b), която приема две числа и връща като резултат сбора им. +2. Да се напише функция isEven(const int num), която връща дали дадено число е четно или не. +3. а)Да се напише функция isPositive(const int num), която връща дали дадено число е положително или не + b)Да се напише функция isNegative(const int num), която връща дали дадено число е отрицателно или не. +4. a)Напишете функция abs(const int num), която връща като резултат абсолютната стойност на числото num. + b)Напишете функция fabs(const double num), която връща като резултат абсолютната стойност на числото num. +5. Напишете функция print(const char S, const int N), която извежда на екрана N-пъти символа S. +6. Напишете функция isCapitalLetter(const char S), която проверява дали даден символ е главна буква. + *Реализирайте функция checkSymbol(const char S), която да проверява дали символът е буква.* +7. a)Напишете функция, която проверява дали дадено число е в интервала [100;10000] + b)Напишете функция, която проверява дали дадено число е в даден интервал. + +8.Напишете функция pow(const int num, const unsigned N), която връща като резултат числото num повдигнато на степен N, където N е строго положително. +9.Напишете функция calculate(const int a, const int b, char action), където action може да бъде [+-*/%]. + Програмата да връща като резултат съответното действие, а ако не се укаже символ да върне сбора на числата +10.Напишете функция, askUser(const int from, const int to), която кара потребителя да въвежда числа докато не въведе число, + което да е в указания интервал, а като резултат връща въпросното число. + +11. Напишете програма, която по въведено число изкарва представянето му в двоична бройна система. + Реализирайте го чрез функция. +12.Да се напише програма, която въвежда стойности на естествените числа a, b, c и d и намира и извежда най-големият общ делител + на числата a и b, след това на c и d и накрая на a, b, c и d. +13.Напишете програма, която получава цяло естествено число в интервала [100;100000]. + Програмата да изведе най - близкото число степен на двойката до това число.(тоест разликата на числата по абсолютна стойност да е минимална). + Входа да се валидира като при грешен ход да се дава възможност за нов опит. + Изкарайте отделните функционалности във функции. + + -- cgit v1.3.1-23-gd82d From 09bbffaca8d060c4cc70438cfd393d0566c47509 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:32:04 +0200 Subject: Update and rename Sem. 04_KN/tasks.cpp to Sem. 04/README.md --- Sem. 04/README.md | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Sem. 04_KN/tasks.cpp | 1 - 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 Sem. 04/README.md delete mode 100644 Sem. 04_KN/tasks.cpp diff --git a/Sem. 04/README.md b/Sem. 04/README.md new file mode 100644 index 0000000..3433548 --- /dev/null +++ b/Sem. 04/README.md @@ -0,0 +1,88 @@ +. +# Функции + +![enter image description here](https://i.ibb.co/PCGYQ71/func.png) +В контекста на _програмирането_, _функциясе нарича именувана група от инструкции, които изпълняват дадена функционалност. + +### Синтаксис +```c++ +<тип на връщане> <идентификатор> (параметър1, параметър ...) +{ + //тяло +} +``` +Всеки параметър се състои от **тип** и **идентификатор**. + +Пример: +```c++ +int max(int n, int k) +{ + return n > k ? n : k; +} +``` +Оператор **return**: + + - Прекратява изпълнението на функцията + - Замества извикването и с резултата (връща резултата) + +Операторът може да се използва и при функции, които не връщат нищо (void функции). Тогава return единствено прекратява функцията. + +### Параметри по копие +**Важно**: Функциите, написани по този начин, приемат своите параметри **по копие**. (Функции, които приемат параметри по референция (не по копие) ще учим по-натам). +```c++ +void f(int n) +{ + n++; +} +int main() +{ + int n = 4; + f(n); + cout << n << endl; //4 +} +``` + + +### Примери: + +**Задача 1:** Въвежда се неотрицателно число n. Да се отпечатат всички двойки прости числа, които са във вида 6k-1 и 6k+1. + +-решена без функции и решена с функции. + +**Задача 2:** Напишете функция, която приема неотрицателно число n и връща числото обърнато + +*Вход: 288, Изход: 882* + +**Задача 3:** Напишете функция, която приема неотрицателно число и връща дали числото е палиндром. + +*Вход: 2882 Изход: true* + +**Задача 4:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е суфикс на n. + +*Вход: 288, 88, Изход: true* + +**Задача 5:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е префикс на n. + +*Вход: 288, 28, Изход: true* + +**Задача 6:** Напишете функция, която приема неотрицателни числа n и k и връща дали k се съдържа в n. + +*Вход: 2831, 83, Изход: true* + +**Задача 7:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са сортирани (във възходящ или в низходящ ред). + +*Вход: 122239, Изход: true* + + +**Задача 8:** Напишете функция, която приема неотрицателно число и връща дали цифрите му са еднакви. + +*Вход: 111111, Изход: true* + +**Задача 9:** Напишете функция, която приема неотрицателно числа n и k връща n^k + +*Вход: 3 4, Изход: 81* + +**Задача 10:** Напишете функция, която приема неотрицателно числа n и k връща log_k(n) (закръглено надолу) + +*Вход: 90 3 Изход: 4* + diff --git a/Sem. 04_KN/tasks.cpp b/Sem. 04_KN/tasks.cpp deleted file mode 100644 index 9c558e3..0000000 --- a/Sem. 04_KN/tasks.cpp +++ /dev/null @@ -1 +0,0 @@ -. -- cgit v1.3.1-23-gd82d From 72c9987765cf118b71bfdc9020e97bcf7f2a999a Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:32:28 +0200 Subject: Update README.md --- Sem. 04/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sem. 04/README.md b/Sem. 04/README.md index 3433548..a56ecd1 100644 --- a/Sem. 04/README.md +++ b/Sem. 04/README.md @@ -2,7 +2,8 @@ # Функции ![enter image description here](https://i.ibb.co/PCGYQ71/func.png) -В контекста на _програмирането_, _функциясе нарича именувана група от инструкции, които изпълняват дадена функционалност. + +В контекста на програмирането, функция се нарича именувана група от инструкции, които изпълняват дадена функционалност. ### Синтаксис ```c++ -- cgit v1.3.1-23-gd82d From 7b48d82f74cfa2a8820cad4c50ca7a916458850a Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:32:57 +0200 Subject: Add files via upload --- Sem. 04/example1_no_functions.cpp | 39 ++++++++++ Sem. 04/example1_with_functions.cpp | 27 +++++++ Sem. 04/examples2-8.cpp | 141 ++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 Sem. 04/example1_no_functions.cpp create mode 100644 Sem. 04/example1_with_functions.cpp create mode 100644 Sem. 04/examples2-8.cpp diff --git a/Sem. 04/example1_no_functions.cpp b/Sem. 04/example1_no_functions.cpp new file mode 100644 index 0000000..06e6629 --- /dev/null +++ b/Sem. 04/example1_no_functions.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + + +int main() +{ + int n; + cin >> n; + + for (int i = 6; i < n; i += 6) + { + int firstToCheck = i - 1; + int secondToCheck = i + 1; + + //prime check + bool isFirstPrime = true; + double temp = sqrt(firstToCheck); + for (int j = 2; j <= temp; j++) + { + if (firstToCheck % j == 0) + isFirstPrime = false; + } + + if (!isFirstPrime) + continue; + + //prime check + bool isSecondPrime = true; + double temp2 = sqrt(secondToCheck); + for (int j = 2; j <= temp2; j++) + { + if (secondToCheck % j == 0) + isSecondPrime = false; + } + + if (isSecondPrime) + cout << firstToCheck << " " << secondToCheck << endl; + } +} \ No newline at end of file diff --git a/Sem. 04/example1_with_functions.cpp b/Sem. 04/example1_with_functions.cpp new file mode 100644 index 0000000..f33b6b9 --- /dev/null +++ b/Sem. 04/example1_with_functions.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +bool isPrime(int n) +{ + double temp = sqrt(n); + + for (int i = 2; i <= temp; i++) + { + if (n % i == 0) + return false; + } + + return true; +} + +int main() +{ + int n; + cin >> n; + + for (int i = 6; i < n; i += 6) + { + if (isPrime(i - 1) && isPrime(i + 1)) + cout << i - 1 << " " << i + 1 << endl; + } +} \ No newline at end of file diff --git a/Sem. 04/examples2-8.cpp b/Sem. 04/examples2-8.cpp new file mode 100644 index 0000000..002a8ab --- /dev/null +++ b/Sem. 04/examples2-8.cpp @@ -0,0 +1,141 @@ +#include +using namespace std; + + +//задача 2: +// Напишете функция, която приема цяло число и връща обърнатото му. +// 1234 - 4321 + +int reverse(unsigned int n) +{ + unsigned int result = 0; + + while (n != 0) + { + int lastDigit = n % 10; + (result *= 10) += lastDigit; + n /= 10; + } + + return result; +} + +//задача 3: Напишете функция, която приема цяло число и връща дали е палиндром + +//12321 -> true +//123 -> false; + +bool isPalindrome(unsigned int n) +{ + return n == reverse(n); +} +//задача 4: Напишете функция, която приема две цели числа - n и k. +//Функцията да връща дали k е суфикс на n. +// n = 1234 k = 34 true +// n = 1234 k = 234 true +// n = 1234 k = 1234 true +// n = 1234 k = 23 false + +bool isSuffix(unsigned int n, unsigned int k) +{ + if (k == 0 && (n % 10 != 0)) + return false; + + while (k != 0) + { + int lastDigitOfN = n % 10; + int lastDigitOfK = k % 10; + + if (lastDigitOfN != lastDigitOfK) + return false; + + n /= 10; + k /= 10; + } + + return true; +} + + +// задача 5: Напишете функция, която приема две цели числа -n и k. +// Функцията да връща дали k е префикс на n. + +// n = 1234, k = 12 true +// n = 1234, k = 23 false; + +// u е префикс на w <-> u ^rev е суфикс на w^rev +bool isPrefix(unsigned int n, unsigned int k) +{ + return isSuffix(reverse(n), reverse(k)); +} + +// задача 6: Напишете функция, която приема две числа - n,k. +// Функцията връща дали k е инфикс на n. + +bool isInfix(unsigned int n, unsigned int k) +{ + if (n == 0 && k == 0) + return true; + + while (n > 0) + { + if (isSuffix(n, k)) + return true; + n /= 10; + } + return false; +} + + +//задача. +//Да се напише функция, която приема цяло число и връща дали цифрите му са сортирани. + +// 1234 true +// 12379 true +// 1231 false +// 4321 true +// 4325 false +// 1111 true + +bool areDigitsSortedAscending(unsigned int n) +{ + while (n >= 10) + { + int lastDigit = n % 10; + int prevLastDigit = (n / 10) % 10; + + if (prevLastDigit > lastDigit) + return false; + + n /= 10; + } + + return true; +} + +bool areDigitsSortedDescending(int n) +{ + return areDigitsSortedAscending(reverse(n)); +} + +bool areDigitsSorted(int n) +{ + return areDigitsSortedDescending(n) || areDigitsSortedAscending(n); +} + +//задача. +// Напишете функция, която приема цяло число и връща дали се съдържа само от еднакви цифри. + +//Вход: 11111 Изход:true +//Вход: 123 Изход: false + +bool containOnlyOneDigit(int n) +{ + return areDigitsSortedDescending(n) && areDigitsSortedAscending(n); +} + + +int main() +{ + cout << containOnlyOneDigit(444) << endl; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 2af7aac08e3bae3ed6e99fe04c32d39acb4bb129 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:34:38 +0200 Subject: Add files via upload --- Sem. 04/example01_no_functions.cpp | 39 ++++++++++ Sem. 04/example01_with_functions.cpp | 27 +++++++ Sem. 04/example02-08.cpp | 141 +++++++++++++++++++++++++++++++++++ Sem. 04/example09 .cpp | 21 ++++++ Sem. 04/example10.cpp | 21 ++++++ 5 files changed, 249 insertions(+) create mode 100644 Sem. 04/example01_no_functions.cpp create mode 100644 Sem. 04/example01_with_functions.cpp create mode 100644 Sem. 04/example02-08.cpp create mode 100644 Sem. 04/example09 .cpp create mode 100644 Sem. 04/example10.cpp diff --git a/Sem. 04/example01_no_functions.cpp b/Sem. 04/example01_no_functions.cpp new file mode 100644 index 0000000..06e6629 --- /dev/null +++ b/Sem. 04/example01_no_functions.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + + +int main() +{ + int n; + cin >> n; + + for (int i = 6; i < n; i += 6) + { + int firstToCheck = i - 1; + int secondToCheck = i + 1; + + //prime check + bool isFirstPrime = true; + double temp = sqrt(firstToCheck); + for (int j = 2; j <= temp; j++) + { + if (firstToCheck % j == 0) + isFirstPrime = false; + } + + if (!isFirstPrime) + continue; + + //prime check + bool isSecondPrime = true; + double temp2 = sqrt(secondToCheck); + for (int j = 2; j <= temp2; j++) + { + if (secondToCheck % j == 0) + isSecondPrime = false; + } + + if (isSecondPrime) + cout << firstToCheck << " " << secondToCheck << endl; + } +} \ No newline at end of file diff --git a/Sem. 04/example01_with_functions.cpp b/Sem. 04/example01_with_functions.cpp new file mode 100644 index 0000000..f33b6b9 --- /dev/null +++ b/Sem. 04/example01_with_functions.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +bool isPrime(int n) +{ + double temp = sqrt(n); + + for (int i = 2; i <= temp; i++) + { + if (n % i == 0) + return false; + } + + return true; +} + +int main() +{ + int n; + cin >> n; + + for (int i = 6; i < n; i += 6) + { + if (isPrime(i - 1) && isPrime(i + 1)) + cout << i - 1 << " " << i + 1 << endl; + } +} \ No newline at end of file diff --git a/Sem. 04/example02-08.cpp b/Sem. 04/example02-08.cpp new file mode 100644 index 0000000..002a8ab --- /dev/null +++ b/Sem. 04/example02-08.cpp @@ -0,0 +1,141 @@ +#include +using namespace std; + + +//задача 2: +// Напишете функция, която приема цяло число и връща обърнатото му. +// 1234 - 4321 + +int reverse(unsigned int n) +{ + unsigned int result = 0; + + while (n != 0) + { + int lastDigit = n % 10; + (result *= 10) += lastDigit; + n /= 10; + } + + return result; +} + +//задача 3: Напишете функция, която приема цяло число и връща дали е палиндром + +//12321 -> true +//123 -> false; + +bool isPalindrome(unsigned int n) +{ + return n == reverse(n); +} +//задача 4: Напишете функция, която приема две цели числа - n и k. +//Функцията да връща дали k е суфикс на n. +// n = 1234 k = 34 true +// n = 1234 k = 234 true +// n = 1234 k = 1234 true +// n = 1234 k = 23 false + +bool isSuffix(unsigned int n, unsigned int k) +{ + if (k == 0 && (n % 10 != 0)) + return false; + + while (k != 0) + { + int lastDigitOfN = n % 10; + int lastDigitOfK = k % 10; + + if (lastDigitOfN != lastDigitOfK) + return false; + + n /= 10; + k /= 10; + } + + return true; +} + + +// задача 5: Напишете функция, която приема две цели числа -n и k. +// Функцията да връща дали k е префикс на n. + +// n = 1234, k = 12 true +// n = 1234, k = 23 false; + +// u е префикс на w <-> u ^rev е суфикс на w^rev +bool isPrefix(unsigned int n, unsigned int k) +{ + return isSuffix(reverse(n), reverse(k)); +} + +// задача 6: Напишете функция, която приема две числа - n,k. +// Функцията връща дали k е инфикс на n. + +bool isInfix(unsigned int n, unsigned int k) +{ + if (n == 0 && k == 0) + return true; + + while (n > 0) + { + if (isSuffix(n, k)) + return true; + n /= 10; + } + return false; +} + + +//задача. +//Да се напише функция, която приема цяло число и връща дали цифрите му са сортирани. + +// 1234 true +// 12379 true +// 1231 false +// 4321 true +// 4325 false +// 1111 true + +bool areDigitsSortedAscending(unsigned int n) +{ + while (n >= 10) + { + int lastDigit = n % 10; + int prevLastDigit = (n / 10) % 10; + + if (prevLastDigit > lastDigit) + return false; + + n /= 10; + } + + return true; +} + +bool areDigitsSortedDescending(int n) +{ + return areDigitsSortedAscending(reverse(n)); +} + +bool areDigitsSorted(int n) +{ + return areDigitsSortedDescending(n) || areDigitsSortedAscending(n); +} + +//задача. +// Напишете функция, която приема цяло число и връща дали се съдържа само от еднакви цифри. + +//Вход: 11111 Изход:true +//Вход: 123 Изход: false + +bool containOnlyOneDigit(int n) +{ + return areDigitsSortedDescending(n) && areDigitsSortedAscending(n); +} + + +int main() +{ + cout << containOnlyOneDigit(444) << endl; +} \ No newline at end of file diff --git a/Sem. 04/example09 .cpp b/Sem. 04/example09 .cpp new file mode 100644 index 0000000..f7f072b --- /dev/null +++ b/Sem. 04/example09 .cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +unsigned int log(unsigned int n, unsigned int k) +{ + int count = 0; + + while (n >= k) + { + n /= k; + count++; + } + + return count; +} + + +int main() +{ + cout << log(4, 10) << endl; +} \ No newline at end of file diff --git a/Sem. 04/example10.cpp b/Sem. 04/example10.cpp new file mode 100644 index 0000000..f7f072b --- /dev/null +++ b/Sem. 04/example10.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +unsigned int log(unsigned int n, unsigned int k) +{ + int count = 0; + + while (n >= k) + { + n /= k; + count++; + } + + return count; +} + + +int main() +{ + cout << log(4, 10) << endl; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From d95311d6fe0b91ee54b4629c09914e5f44a476f9 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:34:50 +0200 Subject: Delete examples2-8.cpp --- Sem. 04/examples2-8.cpp | 141 ------------------------------------------------ 1 file changed, 141 deletions(-) delete mode 100644 Sem. 04/examples2-8.cpp diff --git a/Sem. 04/examples2-8.cpp b/Sem. 04/examples2-8.cpp deleted file mode 100644 index 002a8ab..0000000 --- a/Sem. 04/examples2-8.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include -using namespace std; - - -//задача 2: -// Напишете функция, която приема цяло число и връща обърнатото му. -// 1234 - 4321 - -int reverse(unsigned int n) -{ - unsigned int result = 0; - - while (n != 0) - { - int lastDigit = n % 10; - (result *= 10) += lastDigit; - n /= 10; - } - - return result; -} - -//задача 3: Напишете функция, която приема цяло число и връща дали е палиндром - -//12321 -> true -//123 -> false; - -bool isPalindrome(unsigned int n) -{ - return n == reverse(n); -} -//задача 4: Напишете функция, която приема две цели числа - n и k. -//Функцията да връща дали k е суфикс на n. -// n = 1234 k = 34 true -// n = 1234 k = 234 true -// n = 1234 k = 1234 true -// n = 1234 k = 23 false - -bool isSuffix(unsigned int n, unsigned int k) -{ - if (k == 0 && (n % 10 != 0)) - return false; - - while (k != 0) - { - int lastDigitOfN = n % 10; - int lastDigitOfK = k % 10; - - if (lastDigitOfN != lastDigitOfK) - return false; - - n /= 10; - k /= 10; - } - - return true; -} - - -// задача 5: Напишете функция, която приема две цели числа -n и k. -// Функцията да връща дали k е префикс на n. - -// n = 1234, k = 12 true -// n = 1234, k = 23 false; - -// u е префикс на w <-> u ^rev е суфикс на w^rev -bool isPrefix(unsigned int n, unsigned int k) -{ - return isSuffix(reverse(n), reverse(k)); -} - -// задача 6: Напишете функция, която приема две числа - n,k. -// Функцията връща дали k е инфикс на n. - -bool isInfix(unsigned int n, unsigned int k) -{ - if (n == 0 && k == 0) - return true; - - while (n > 0) - { - if (isSuffix(n, k)) - return true; - n /= 10; - } - return false; -} - - -//задача. -//Да се напише функция, която приема цяло число и връща дали цифрите му са сортирани. - -// 1234 true -// 12379 true -// 1231 false -// 4321 true -// 4325 false -// 1111 true - -bool areDigitsSortedAscending(unsigned int n) -{ - while (n >= 10) - { - int lastDigit = n % 10; - int prevLastDigit = (n / 10) % 10; - - if (prevLastDigit > lastDigit) - return false; - - n /= 10; - } - - return true; -} - -bool areDigitsSortedDescending(int n) -{ - return areDigitsSortedAscending(reverse(n)); -} - -bool areDigitsSorted(int n) -{ - return areDigitsSortedDescending(n) || areDigitsSortedAscending(n); -} - -//задача. -// Напишете функция, която приема цяло число и връща дали се съдържа само от еднакви цифри. - -//Вход: 11111 Изход:true -//Вход: 123 Изход: false - -bool containOnlyOneDigit(int n) -{ - return areDigitsSortedDescending(n) && areDigitsSortedAscending(n); -} - - -int main() -{ - cout << containOnlyOneDigit(444) << endl; -} \ No newline at end of file -- cgit v1.3.1-23-gd82d From b29cf210a7af3ae789e8067a88b7421dfc58e6a6 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:34:57 +0200 Subject: Delete example1_no_functions.cpp --- Sem. 04/example1_no_functions.cpp | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 Sem. 04/example1_no_functions.cpp diff --git a/Sem. 04/example1_no_functions.cpp b/Sem. 04/example1_no_functions.cpp deleted file mode 100644 index 06e6629..0000000 --- a/Sem. 04/example1_no_functions.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -using namespace std; - - -int main() -{ - int n; - cin >> n; - - for (int i = 6; i < n; i += 6) - { - int firstToCheck = i - 1; - int secondToCheck = i + 1; - - //prime check - bool isFirstPrime = true; - double temp = sqrt(firstToCheck); - for (int j = 2; j <= temp; j++) - { - if (firstToCheck % j == 0) - isFirstPrime = false; - } - - if (!isFirstPrime) - continue; - - //prime check - bool isSecondPrime = true; - double temp2 = sqrt(secondToCheck); - for (int j = 2; j <= temp2; j++) - { - if (secondToCheck % j == 0) - isSecondPrime = false; - } - - if (isSecondPrime) - cout << firstToCheck << " " << secondToCheck << endl; - } -} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 57574519b81b9e83a13ad963398634cf00d36007 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:35:03 +0200 Subject: Delete example1_with_functions.cpp --- Sem. 04/example1_with_functions.cpp | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 Sem. 04/example1_with_functions.cpp diff --git a/Sem. 04/example1_with_functions.cpp b/Sem. 04/example1_with_functions.cpp deleted file mode 100644 index f33b6b9..0000000 --- a/Sem. 04/example1_with_functions.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -using namespace std; - -bool isPrime(int n) -{ - double temp = sqrt(n); - - for (int i = 2; i <= temp; i++) - { - if (n % i == 0) - return false; - } - - return true; -} - -int main() -{ - int n; - cin >> n; - - for (int i = 6; i < n; i += 6) - { - if (isPrime(i - 1) && isPrime(i + 1)) - cout << i - 1 << " " << i + 1 << endl; - } -} \ No newline at end of file -- cgit v1.3.1-23-gd82d From 4ffc24fb6c30ed7feda44a9c4f35056c5e2bff36 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:35:52 +0200 Subject: Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1004739..9a25dcb 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ - **Тема 1:** Увод. Примитивни типове данни. Преобразуване между типове. Оператори. - **Тема 2:** Условни конструкции - if, switch и тернарен оператор. - **Тема 3:** Цикли. Оператори break и continue. + - **Тема 4:** Функции. ### Практикум: -- cgit v1.3.1-23-gd82d From 76f1bc24428d2527974cad61f60b9acc577054fe Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 14:36:07 +0200 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a25dcb..8afebbd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ - **Тема 1:** Увод. Примитивни типове данни. Преобразуване между типове. Оператори. - **Тема 2:** Условни конструкции - if, switch и тернарен оператор. - **Тема 3:** Цикли. Оператори break и continue. - - **Тема 4:** Функции. + - **Тема 4:** Функции. Оператор return. ### Практикум: -- cgit v1.3.1-23-gd82d From 01016f0f0540a15db4a7cf900a9fc42133b1964a Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 15:01:08 +0200 Subject: Update README.md --- Sem. 04/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sem. 04/README.md b/Sem. 04/README.md index a56ecd1..0135d76 100644 --- a/Sem. 04/README.md +++ b/Sem. 04/README.md @@ -87,3 +87,30 @@ int main() *Вход: 90 3 Изход: 4* +

Задачи

+ +**Задача 1:** Напишете функция, която приема цяло число и връща модула му. + +*Вход: 4, Изход: 4* + +*Вход: -4, Изход: 4* + +*Вход: 5 4 3 0 Изход: 12* + +**Задача 2:** Напишете функция, която приема 4 цели числа - координати на 2 точки. Функцията да връща разстоянието между тези точки. + +*Вход: 1 1 4 3, Изход: 6.403* + +**Задача 3:** Напишете функция, която приема 6 целочислени координати (3 точки) и връща обиколката на триъгълника по тези точки. + +*Вход: 1 1 4 7 0 10, Изход: 20.764* + +**Задача 4:** Да се напише функция, която приема три естествени числа a и b и k отпечатва всички числа в интервата [a...b], които имат точно k различни прости делители. +*Вход: 19 32 3, Изход: 20 30* +*Вход: 19 32 1, Изход: 19 23 29 31* +**Задача 4:** Да се напише функция, която приема естествено число n и отпечатва всички двойки , такива че a и b са прости и a + b = n. + +**Задача 5:** Да се напише функция, която приема две естествени числа a и b и отпечава всички числа k и интервала [a,b], такива че k = x^y (за някои ест. числа x и y) +*Вход: 15 30, Изход: 16 25 27* , защото (4^2, 5^2, 3^3) + + -- cgit v1.3.1-23-gd82d From 0fa86a114caa8384886fa20ba73803e69938d6f8 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 15:01:32 +0200 Subject: Update README.md --- Sem. 04/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sem. 04/README.md b/Sem. 04/README.md index 0135d76..55b21b0 100644 --- a/Sem. 04/README.md +++ b/Sem. 04/README.md @@ -108,9 +108,10 @@ int main() **Задача 4:** Да се напише функция, която приема три естествени числа a и b и k отпечатва всички числа в интервата [a...b], които имат точно k различни прости делители. *Вход: 19 32 3, Изход: 20 30* *Вход: 19 32 1, Изход: 19 23 29 31* -**Задача 4:** Да се напише функция, която приема естествено число n и отпечатва всички двойки , такива че a и b са прости и a + b = n. -**Задача 5:** Да се напише функция, която приема две естествени числа a и b и отпечава всички числа k и интервала [a,b], такива че k = x^y (за някои ест. числа x и y) +**Задача 5:** Да се напише функция, която приема естествено число n и отпечатва всички двойки , такива че a и b са прости и a + b = n. + +**Задача 6:** Да се напише функция, която приема две естествени числа a и b и отпечава всички числа k и интервала [a,b], такива че k = x^y (за някои ест. числа x и y) *Вход: 15 30, Изход: 16 25 27* , защото (4^2, 5^2, 3^3) -- cgit v1.3.1-23-gd82d From 576ea3051a88b2c740c816467a6761a888b5ef3f Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 15:03:26 +0200 Subject: Create exercise01.cpp --- Sem. 04/Solutions/exercise01.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Sem. 04/Solutions/exercise01.cpp diff --git a/Sem. 04/Solutions/exercise01.cpp b/Sem. 04/Solutions/exercise01.cpp new file mode 100644 index 0000000..edc9c9c --- /dev/null +++ b/Sem. 04/Solutions/exercise01.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int mod(int n) +{ + return n < 0 ? -n : n; +} +int main() +{ + cout << mod(-4) << endl; +} -- cgit v1.3.1-23-gd82d From a0d9a533e6e4f6b5b06fff9268e9bf6233ef3eef Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 15:04:04 +0200 Subject: Update README.md --- Sem. 04/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 04/README.md b/Sem. 04/README.md index 55b21b0..d6f9af9 100644 --- a/Sem. 04/README.md +++ b/Sem. 04/README.md @@ -87,7 +87,7 @@ int main() *Вход: 90 3 Изход: 4* -

Задачи

+

Задачи:

**Задача 1:** Напишете функция, която приема цяло число и връща модула му. -- cgit v1.3.1-23-gd82d From 15b1685a4c684b5498473ff1cefa1767bc655d49 Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Tue, 2 Nov 2021 16:23:43 +0200 Subject: Edit&Rename --- pract_SI/Pract. 04/Task4.txt | 32 -------------------------------- pract_SI/Pract. 04/Tasks4.txt | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 pract_SI/Pract. 04/Task4.txt create mode 100644 pract_SI/Pract. 04/Tasks4.txt diff --git a/pract_SI/Pract. 04/Task4.txt b/pract_SI/Pract. 04/Task4.txt deleted file mode 100644 index cc5f735..0000000 --- a/pract_SI/Pract. 04/Task4.txt +++ /dev/null @@ -1,32 +0,0 @@ -#Никола Светославов - task4 - -## Задачи - -1. Да се състави функция sum(const int a, const int b), която приема две числа и връща като резултат сбора им. -2. Да се напише функция isEven(const int num), която връща дали дадено число е четно или не. -3. а)Да се напише функция isPositive(const int num), която връща дали дадено число е положително или не - b)Да се напише функция isNegative(const int num), която връща дали дадено число е отрицателно или не. -4. a)Напишете функция abs(const int num), която връща като резултат абсолютната стойност на числото num. - b)Напишете функция fabs(const double num), която връща като резултат абсолютната стойност на числото num. -5. Напишете функция print(const char S, const int N), която извежда на екрана N-пъти символа S. -6. Напишете функция isCapitalLetter(const char S), която проверява дали даден символ е главна буква. - *Реализирайте функция checkSymbol(const char S), която да проверява дали символът е буква.* -7. a)Напишете функция, която проверява дали дадено число е в интервала [100;10000] - b)Напишете функция, която проверява дали дадено число е в даден интервал. - -8.Напишете функция pow(const int num, const unsigned N), която връща като резултат числото num повдигнато на степен N, където N е строго положително. -9.Напишете функция calculate(const int a, const int b, char action), където action може да бъде [+-*/%]. - Програмата да връща като резултат съответното действие, а ако не се укаже символ да върне сбора на числата -10.Напишете функция, askUser(const int from, const int to), която кара потребителя да въвежда числа докато не въведе число, - което да е в указания интервал, а като резултат връща въпросното число. - -11. Напишете програма, която по въведено число изкарва представянето му в двоична бройна система. - Реализирайте го чрез функция. -12.Да се напише програма, която въвежда стойности на естествените числа a, b, c и d и намира и извежда най-големият общ делител - на числата a и b, след това на c и d и накрая на a, b, c и d. -13.Напишете програма, която получава цяло естествено число в интервала [100;100000]. - Програмата да изведе най - близкото число степен на двойката до това число.(тоест разликата на числата по абсолютна стойност да е минимална). - Входа да се валидира като при грешен ход да се дава възможност за нов опит. - Изкарайте отделните функционалности във функции. - - diff --git a/pract_SI/Pract. 04/Tasks4.txt b/pract_SI/Pract. 04/Tasks4.txt new file mode 100644 index 0000000..cc5f735 --- /dev/null +++ b/pract_SI/Pract. 04/Tasks4.txt @@ -0,0 +1,32 @@ +#Никола Светославов - task4 + +## Задачи + +1. Да се състави функция sum(const int a, const int b), която приема две числа и връща като резултат сбора им. +2. Да се напише функция isEven(const int num), която връща дали дадено число е четно или не. +3. а)Да се напише функция isPositive(const int num), която връща дали дадено число е положително или не + b)Да се напише функция isNegative(const int num), която връща дали дадено число е отрицателно или не. +4. a)Напишете функция abs(const int num), която връща като резултат абсолютната стойност на числото num. + b)Напишете функция fabs(const double num), която връща като резултат абсолютната стойност на числото num. +5. Напишете функция print(const char S, const int N), която извежда на екрана N-пъти символа S. +6. Напишете функция isCapitalLetter(const char S), която проверява дали даден символ е главна буква. + *Реализирайте функция checkSymbol(const char S), която да проверява дали символът е буква.* +7. a)Напишете функция, която проверява дали дадено число е в интервала [100;10000] + b)Напишете функция, която проверява дали дадено число е в даден интервал. + +8.Напишете функция pow(const int num, const unsigned N), която връща като резултат числото num повдигнато на степен N, където N е строго положително. +9.Напишете функция calculate(const int a, const int b, char action), където action може да бъде [+-*/%]. + Програмата да връща като резултат съответното действие, а ако не се укаже символ да върне сбора на числата +10.Напишете функция, askUser(const int from, const int to), която кара потребителя да въвежда числа докато не въведе число, + което да е в указания интервал, а като резултат връща въпросното число. + +11. Напишете програма, която по въведено число изкарва представянето му в двоична бройна система. + Реализирайте го чрез функция. +12.Да се напише програма, която въвежда стойности на естествените числа a, b, c и d и намира и извежда най-големият общ делител + на числата a и b, след това на c и d и накрая на a, b, c и d. +13.Напишете програма, която получава цяло естествено число в интервала [100;100000]. + Програмата да изведе най - близкото число степен на двойката до това число.(тоест разликата на числата по абсолютна стойност да е минимална). + Входа да се валидира като при грешен ход да се дава възможност за нов опит. + Изкарайте отделните функционалности във функции. + + -- cgit v1.3.1-23-gd82d From e55e9fb058a046f6f1e08da521660a8d98b1d5db Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Tue, 2 Nov 2021 16:23:53 +0200 Subject: Added Solutions --- pract_SI/Pract. 04/Solutions/task1.cpp | 34 +++++++++++++++++++++++ pract_SI/Pract. 04/Solutions/task2 - example1.cpp | 23 +++++++++++++++ pract_SI/Pract. 04/Solutions/task2 - example2.cpp | 25 +++++++++++++++++ pract_SI/Pract. 04/Solutions/task3.cpp | 8 ++++++ pract_SI/Pract. 04/Solutions/task4.cpp | 4 +++ pract_SI/Pract. 04/Solutions/task5.cpp | 20 +++++++++++++ pract_SI/Pract. 04/function overload.cpp | 16 +++++++++++ 7 files changed, 130 insertions(+) create mode 100644 pract_SI/Pract. 04/Solutions/task1.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task2 - example1.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task2 - example2.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task3.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task4.cpp create mode 100644 pract_SI/Pract. 04/Solutions/task5.cpp create mode 100644 pract_SI/Pract. 04/function overload.cpp diff --git a/pract_SI/Pract. 04/Solutions/task1.cpp b/pract_SI/Pract. 04/Solutions/task1.cpp new file mode 100644 index 0000000..3e8c1a3 --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task1.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +int sum(const int a, const int b) +{ + /* + //First way + int sum = a + b; + return sum; + */ + + //Second way + return a + b; +} + +int main() +{ + int num1, num2; + cin >> num1 >> num2; + + //First way + cout << sum(num1, num2) << endl; //return as output on Console + + /* + //Second way + //int sumOfNumbers = sum(num1, num2); //create an int with value num1+num2; + //cout << sumOfNumbers << endl; + */ + + return 0; +} + + diff --git a/pract_SI/Pract. 04/Solutions/task2 - example1.cpp b/pract_SI/Pract. 04/Solutions/task2 - example1.cpp new file mode 100644 index 0000000..309e68d --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task2 - example1.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +bool isZero(const int number) +{ + return (number == 0); +} + +bool isEven(const int number) +{ + if (isZero(number)) + { + return false; + } + return !(number % 2); +} + +int main() +{ + int n; + cin >> n; + cout << boolalpha << isEven(n) << endl; + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task2 - example2.cpp b/pract_SI/Pract. 04/Solutions/task2 - example2.cpp new file mode 100644 index 0000000..0440873 --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task2 - example2.cpp @@ -0,0 +1,25 @@ +#include + +bool isEven(const int num) { + return !(num % 2); +} + +bool isZero(const int num) { + return num == 0; +} + +int main() { + int num; + std::cin >> num; + if (isZero(num)) { + std::cout << "The number is not ever or odd!"; + } + else { + if (isEven(num)) { + std::cout << "Even"; + return 0; + } + std::cout << "Odd"; + } + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task3.cpp b/pract_SI/Pract. 04/Solutions/task3.cpp new file mode 100644 index 0000000..bc85d3a --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task3.cpp @@ -0,0 +1,8 @@ +bool isPositive(const int num) +{ + if (num <= 0) + { + return false; + } + return true; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task4.cpp b/pract_SI/Pract. 04/Solutions/task4.cpp new file mode 100644 index 0000000..771550b --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task4.cpp @@ -0,0 +1,4 @@ +int abs(int num1, int num2) +{ + return ((num1 - num2) >= 0 ? (num1 - num2) : (num2 - num1)); +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task5.cpp b/pract_SI/Pract. 04/Solutions/task5.cpp new file mode 100644 index 0000000..fc5552e --- /dev/null +++ b/pract_SI/Pract. 04/Solutions/task5.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; +void print(const int N, const char S = ' ') + { + for (size_t i = 0; i < N; i++) + { + cout << S; + } + } + +int main() +{ + int N; + char S; + cin >> N >> S; + print(N); + cout<< "Error!" << endl; + print(N, S); + return 0; +} \ No newline at end of file diff --git a/pract_SI/Pract. 04/function overload.cpp b/pract_SI/Pract. 04/function overload.cpp new file mode 100644 index 0000000..7e0bdfa --- /dev/null +++ b/pract_SI/Pract. 04/function overload.cpp @@ -0,0 +1,16 @@ +void print() //print - arguments: 0 +{ + cout << "Hello World!\n"; +} + +void print(int number) //print - arguments: 1 + //int +{ + cout << "Hello World N" << number << endl; +} + +void print(double number) //print - arguments: 1 + //double +{ + cout << "Hello World N" << number << endl; +} -- cgit v1.3.1-23-gd82d From 22de45baa822ad542c78f65b2e51956834cfa4c0 Mon Sep 17 00:00:00 2001 From: Stoycho Kyosev <68247567+stoychoX@users.noreply.github.com> Date: Tue, 2 Nov 2021 17:08:08 +0200 Subject: Add files via upload --- ...320\265\320\264\320\274\320\270\321\206\320\260.pdf" | Bin 0 -> 84915 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "pract_KN/pract. 04/\320\227\320\260\320\264\320\260\321\207\320\270 \321\207\320\265\321\202\320\262\321\212\321\200\321\202\320\260 \321\201\320\265\320\264\320\274\320\270\321\206\320\260.pdf" diff --git "a/pract_KN/pract. 04/\320\227\320\260\320\264\320\260\321\207\320\270 \321\207\320\265\321\202\320\262\321\212\321\200\321\202\320\260 \321\201\320\265\320\264\320\274\320\270\321\206\320\260.pdf" "b/pract_KN/pract. 04/\320\227\320\260\320\264\320\260\321\207\320\270 \321\207\320\265\321\202\320\262\321\212\321\200\321\202\320\260 \321\201\320\265\320\264\320\274\320\270\321\206\320\260.pdf" new file mode 100644 index 0000000..88f53b4 Binary files /dev/null and "b/pract_KN/pract. 04/\320\227\320\260\320\264\320\260\321\207\320\270 \321\207\320\265\321\202\320\262\321\212\321\200\321\202\320\260 \321\201\320\265\320\264\320\274\320\270\321\206\320\260.pdf" differ -- cgit v1.3.1-23-gd82d From 84591aa00535f2b036418b38fa8f070ae98a372d Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 12:04:37 -0400 Subject: Update README.md --- Sem. 04/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 04/README.md b/Sem. 04/README.md index d6f9af9..1d5fcb8 100644 --- a/Sem. 04/README.md +++ b/Sem. 04/README.md @@ -66,7 +66,7 @@ int main() *Вход: 288, 28, Изход: true* -**Задача 6:** Напишете функция, която приема неотрицателни числа n и k и връща дали k се съдържа в n. +**Задача 6:** Напишете функция, която приема неотрицателни числа n и k и връща дали k е инфикс в n. *Вход: 2831, 83, Изход: true* -- cgit v1.3.1-23-gd82d From dbf8849b92ede2983940d0496fe5b9f43b8b9bba Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 12:11:43 -0400 Subject: Create kn.txt --- Utils/kn.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Utils/kn.txt diff --git a/Utils/kn.txt b/Utils/kn.txt new file mode 100644 index 0000000..cd672a5 --- /dev/null +++ b/Utils/kn.txt @@ -0,0 +1 @@ +06 -- cgit v1.3.1-23-gd82d From 360b182835727a43d426f5df2de3184cb91ca035 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Tue, 2 Nov 2021 13:14:54 -0400 Subject: Delete kn.txt --- Utils/kn.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Utils/kn.txt diff --git a/Utils/kn.txt b/Utils/kn.txt deleted file mode 100644 index cd672a5..0000000 --- a/Utils/kn.txt +++ /dev/null @@ -1 +0,0 @@ -06 -- cgit v1.3.1-23-gd82d From 83372bc2f825327fa194e6ea71259b1f54234e6d Mon Sep 17 00:00:00 2001 From: Stoycho Kyosev <68247567+stoychoX@users.noreply.github.com> Date: Wed, 3 Nov 2021 00:45:27 +0200 Subject: Add files via upload --- pract_KN/pract. 04/solutions/solutions.cpp | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 pract_KN/pract. 04/solutions/solutions.cpp diff --git a/pract_KN/pract. 04/solutions/solutions.cpp b/pract_KN/pract. 04/solutions/solutions.cpp new file mode 100644 index 0000000..7a1df9f --- /dev/null +++ b/pract_KN/pract. 04/solutions/solutions.cpp @@ -0,0 +1,64 @@ +#include + +int sumInInterval(int n, int m) { + int result = 0; + for (int i = n; i <= m; i++) + result += i; + + return result; +} + +double power(double number, int n) { + double result = 1; + for (int i = 0; i < n; i++) + result *= n; + return result; +} + +int absolute(int n) { + if (n < 0) + return -n; + return n; +} + +double dist(double x1, double y1, double x2, double y2) { + return sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1)); +} + +double perimeter(double x1, double y1, double x2, double y2, double x3, double y3) { + return dist(x1, y1, x2, y2) + dist(x1, y1, x3, y3) + dist(x2, y2, x3, y3); +} + +int fact(int n) { + int result = 1; + for (int i = 1; i <= n; i++) + result *= i; + return result; +} + +bool isNumber(char n) { + return (n >= '0' && n <= '9'); +} + +//Защо това работи? +int f(int a, int b) { + return (a + b) * (a + b + 1) / 2 + b; +} + +void play() { + int computerNumber = rand() % 100 + 1; + int myNumber = 0; + while (myNumber != computerNumber) { + std::cout << "Enter a number -> "; + std::cin >> myNumber; + if (myNumber > computerNumber) + std::cout << "Try smaller number" << std::endl; + else if (myNumber < computerNumber) + std::cout << "Try bigger number" << std::endl; + } + std::cout << "Rigth!!!" << std::endl; +} + +int main() { + //(...) +} \ No newline at end of file -- cgit v1.3.1-23-gd82d From ce08cf91ecb8064b61b6851efea044600d8f99c9 Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Wed, 3 Nov 2021 02:05:51 +0200 Subject: Edit Task4 --- pract_SI/Pract. 04/Tasks4.txt | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pract_SI/Pract. 04/Tasks4.txt b/pract_SI/Pract. 04/Tasks4.txt index cc5f735..4daf06c 100644 --- a/pract_SI/Pract. 04/Tasks4.txt +++ b/pract_SI/Pract. 04/Tasks4.txt @@ -2,25 +2,25 @@ ## Задачи -1. Да се състави функция sum(const int a, const int b), която приема две числа и връща като резултат сбора им. -2. Да се напише функция isEven(const int num), която връща дали дадено число е четно или не. -3. а)Да се напише функция isPositive(const int num), която връща дали дадено число е положително или не - b)Да се напише функция isNegative(const int num), която връща дали дадено число е отрицателно или не. -4. a)Напишете функция abs(const int num), която връща като резултат абсолютната стойност на числото num. - b)Напишете функция fabs(const double num), която връща като резултат абсолютната стойност на числото num. -5. Напишете функция print(const char S, const int N), която извежда на екрана N-пъти символа S. -6. Напишете функция isCapitalLetter(const char S), която проверява дали даден символ е главна буква. - *Реализирайте функция checkSymbol(const char S), която да проверява дали символът е буква.* +1. Да се състави функция sum(int a, int b), която приема две числа и връща като резултат сбора им. +2. Да се напише функция isEven(int num), която връща дали дадено число е четно или не. +3. а)Да се напише функция isPositive(int num), която връща дали дадено число е положително или не + b)Да се напише функция isNegative(int num), която връща дали дадено число е отрицателно или не. +4. a)Напишете функция abs(int num), която връща като резултат абсолютната стойност на числото num. + b)Напишете функция fabs(double num), която връща като резултат абсолютната стойност на числото num. +5. Напишете функция print(char S,int N), която извежда на екрана N-пъти символа S. +6. Напишете функция isCapitalLetter(char S), която проверява дали даден символ е главна буква. + *Реализирайте функция checkSymbol(char S), която да проверява дали символът е буква.* 7. a)Напишете функция, която проверява дали дадено число е в интервала [100;10000] b)Напишете функция, която проверява дали дадено число е в даден интервал. -8.Напишете функция pow(const int num, const unsigned N), която връща като резултат числото num повдигнато на степен N, където N е строго положително. -9.Напишете функция calculate(const int a, const int b, char action), където action може да бъде [+-*/%]. +8.Напишете функция pow(int num,unsigned N), която връща като резултат числото num повдигнато на степен N, където N е строго положително. +9.Напишете функция calculate(nt a,int b, char action), където action може да бъде [+-*/%]. Програмата да връща като резултат съответното действие, а ако не се укаже символ да върне сбора на числата -10.Напишете функция, askUser(const int from, const int to), която кара потребителя да въвежда числа докато не въведе число, +10.Напишете функция, askUser(int from, int to), която кара потребителя да въвежда числа докато не въведе число, което да е в указания интервал, а като резултат връща въпросното число. -11. Напишете програма, която по въведено число изкарва представянето му в двоична бройна система. +11.Напишете програма, която по въведено число изкарва представянето му в двоична бройна система. Реализирайте го чрез функция. 12.Да се напише програма, която въвежда стойности на естествените числа a, b, c и d и намира и извежда най-големият общ делител на числата a и b, след това на c и d и накрая на a, b, c и d. -- cgit v1.3.1-23-gd82d From a43727c44eaeb3164f3ce289a7d08d2974b2a59a Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Wed, 3 Nov 2021 02:10:08 +0200 Subject: Update Pract. Solutions --- pract_SI/Pract. 04/Solutions/task1.cpp | 2 +- pract_SI/Pract. 04/Solutions/task2 - example1.cpp | 10 +--------- pract_SI/Pract. 04/Solutions/task2 - example2.cpp | 24 ++++++++--------------- pract_SI/Pract. 04/Solutions/task3.cpp | 4 +--- pract_SI/Pract. 04/Solutions/task5.cpp | 2 +- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/pract_SI/Pract. 04/Solutions/task1.cpp b/pract_SI/Pract. 04/Solutions/task1.cpp index 3e8c1a3..b56d6e1 100644 --- a/pract_SI/Pract. 04/Solutions/task1.cpp +++ b/pract_SI/Pract. 04/Solutions/task1.cpp @@ -2,7 +2,7 @@ using namespace std; -int sum(const int a, const int b) +int sum(int a, int b) { /* //First way diff --git a/pract_SI/Pract. 04/Solutions/task2 - example1.cpp b/pract_SI/Pract. 04/Solutions/task2 - example1.cpp index 309e68d..25b4030 100644 --- a/pract_SI/Pract. 04/Solutions/task2 - example1.cpp +++ b/pract_SI/Pract. 04/Solutions/task2 - example1.cpp @@ -1,16 +1,8 @@ #include using namespace std; -bool isZero(const int number) -{ - return (number == 0); -} -bool isEven(const int number) +bool isEven(int number) { - if (isZero(number)) - { - return false; - } return !(number % 2); } diff --git a/pract_SI/Pract. 04/Solutions/task2 - example2.cpp b/pract_SI/Pract. 04/Solutions/task2 - example2.cpp index 0440873..2d365ba 100644 --- a/pract_SI/Pract. 04/Solutions/task2 - example2.cpp +++ b/pract_SI/Pract. 04/Solutions/task2 - example2.cpp @@ -1,25 +1,17 @@ #include -bool isEven(const int num) { +bool isEven(int num) { return !(num % 2); } -bool isZero(const int num) { - return num == 0; -} - -int main() { +int main() +{ int num; std::cin >> num; - if (isZero(num)) { - std::cout << "The number is not ever or odd!"; - } - else { - if (isEven(num)) { - std::cout << "Even"; - return 0; - } - std::cout << "Odd"; - } + + if (isEven(num)) + std::cout << "Even"; + else + std::cout << "Odd"; return 0; } \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task3.cpp b/pract_SI/Pract. 04/Solutions/task3.cpp index bc85d3a..60622e2 100644 --- a/pract_SI/Pract. 04/Solutions/task3.cpp +++ b/pract_SI/Pract. 04/Solutions/task3.cpp @@ -1,8 +1,6 @@ -bool isPositive(const int num) +bool isPositive(int num) { if (num <= 0) - { return false; - } return true; } \ No newline at end of file diff --git a/pract_SI/Pract. 04/Solutions/task5.cpp b/pract_SI/Pract. 04/Solutions/task5.cpp index fc5552e..42b5fc6 100644 --- a/pract_SI/Pract. 04/Solutions/task5.cpp +++ b/pract_SI/Pract. 04/Solutions/task5.cpp @@ -1,6 +1,6 @@ #include using namespace std; -void print(const int N, const char S = ' ') +void print(int N, char S = ' ') { for (size_t i = 0; i < N; i++) { -- cgit v1.3.1-23-gd82d From 99905d88c0e6c4c35472a9058e256883d19f4afd Mon Sep 17 00:00:00 2001 From: Justsvetoslavov Date: Wed, 3 Nov 2021 02:18:52 +0200 Subject: Update/Refactor --- pract_SI/Pract. 04/Solutions/task3.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pract_SI/Pract. 04/Solutions/task3.cpp b/pract_SI/Pract. 04/Solutions/task3.cpp index 60622e2..937b833 100644 --- a/pract_SI/Pract. 04/Solutions/task3.cpp +++ b/pract_SI/Pract. 04/Solutions/task3.cpp @@ -1,6 +1,4 @@ bool isPositive(int num) { - if (num <= 0) - return false; - return true; + return (num > 0); } \ No newline at end of file -- cgit v1.3.1-23-gd82d From 771f48b96a1db631a04942c0988fdf8f7a364d2b Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 13:25:03 +0200 Subject: Update README.md --- Sem. 03/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sem. 03/README.md b/Sem. 03/README.md index dae7155..768614b 100644 --- a/Sem. 03/README.md +++ b/Sem. 03/README.md @@ -160,5 +160,7 @@ do +**Задача 15:** Да се напише програма, която приема цяло положително число n и отпечатва следната папионка: +![enter image description here](https://i.ibb.co/FhvpYHP/pap.png) -- cgit v1.3.1-23-gd82d From 7f3e540097425cde3356de7d27e5b47e977ccaa0 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 13:28:45 +0200 Subject: Update drawing_examples.txt --- Sem. 03/drawing_examples.txt | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Sem. 03/drawing_examples.txt b/Sem. 03/drawing_examples.txt index d8fad73..d50ae16 100644 --- a/Sem. 03/drawing_examples.txt +++ b/Sem. 03/drawing_examples.txt @@ -120,6 +120,13 @@ $ $ $ $ . . . . . . . . . . . +вход: 5 +. . . . . . . . . . +. . . . +. . . . . . . +. . . . +. . . . . . . . . . + @@ -153,3 +160,30 @@ $ $ $ $ 1 121 1 + +задача 15: + +вход: 3 + +1 1 +1 2 2 1 +1 2 3 --- 3 2 1 +1 2 2 1 +1 1 + +вход: 4 +1 1 +1 2 2 1 +1 2 3 3 2 1 +1 2 3 4 -------- 4 3 2 1 +1 2 3 3 2 1 +1 2 2 1 +1 1 + + +вход: 2 + +1 1 +1 2 – 2 1 +1 1 + -- cgit v1.3.1-23-gd82d From 5f907f416b30533da40965c54463fa3b953b9db4 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 16:15:22 +0200 Subject: Update drawing_examples.txt --- Sem. 03/drawing_examples.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Sem. 03/drawing_examples.txt b/Sem. 03/drawing_examples.txt index d50ae16..73e3130 100644 --- a/Sem. 03/drawing_examples.txt +++ b/Sem. 03/drawing_examples.txt @@ -172,18 +172,19 @@ $ $ $ $ 1 1 вход: 4 -1 1 -1 2 2 1 -1 2 3 3 2 1 -1 2 3 4 -------- 4 3 2 1 -1 2 3 3 2 1 -1 2 2 1 -1 1 +1 1 +1 2 2 1 +1 2 3 3 2 1 +1 2 3 4 ---- 4 3 2 1 +1 2 3 3 2 1 +1 2 2 1 +1 1 вход: 2 -1 1 -1 2 – 2 1 -1 1 +1 1 +1 2 –- 2 1 +1 1 + -- cgit v1.3.1-23-gd82d From e9b2e3066d218e673eca87959205772cf72b95b4 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 16:16:51 +0200 Subject: Update README.md --- Sem. 03/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 03/README.md b/Sem. 03/README.md index 768614b..35624d4 100644 --- a/Sem. 03/README.md +++ b/Sem. 03/README.md @@ -161,6 +161,6 @@ do **Задача 15:** Да се напише програма, която приема цяло положително число n и отпечатва следната папионка: -![enter image description here](https://i.ibb.co/FhvpYHP/pap.png) +![enter image description here](https://i.ibb.co/NKSPm4z/ddz.png) -- cgit v1.3.1-23-gd82d From 1d126d6a6aa59e7c3aadc3943b80395bb28865ef Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 18:00:27 +0200 Subject: Update README.md --- Sem. 04/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 04/README.md b/Sem. 04/README.md index 1d5fcb8..8e8acb0 100644 --- a/Sem. 04/README.md +++ b/Sem. 04/README.md @@ -99,7 +99,7 @@ int main() **Задача 2:** Напишете функция, която приема 4 цели числа - координати на 2 точки. Функцията да връща разстоянието между тези точки. -*Вход: 1 1 4 3, Изход: 6.403* +*Вход: 1 1 4 3, Изход: 3,605* **Задача 3:** Напишете функция, която приема 6 целочислени координати (3 точки) и връща обиколката на триъгълника по тези точки. -- cgit v1.3.1-23-gd82d From 90d1e842ee65040064207e53bf204d4d9b32d547 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 18:19:49 +0200 Subject: Create exercise 15.cpp --- Sem. 03/solutions/exercise 15.cpp | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Sem. 03/solutions/exercise 15.cpp diff --git a/Sem. 03/solutions/exercise 15.cpp b/Sem. 03/solutions/exercise 15.cpp new file mode 100644 index 0000000..652a201 --- /dev/null +++ b/Sem. 03/solutions/exercise 15.cpp @@ -0,0 +1,58 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + int spacesCount = 2 * (n - 1) + n + 2 * (n - 1); + int toGuess; + for (int i = 1; i <= n - 1; i++) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount -= 4; + + cout << endl; + + } + + //mid + for (int i = 1; i <= n; i++) + cout << i << " "; + for (int i = 0; i < n; i++) + cout << '-'; + for (int i = n; i >= 1; i--) + cout << " " << i; + cout << endl; + + + //down + spacesCount += 4; + for (int i = n - 1; i >= 0; i--) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount += 4; + + cout << endl; + + } + + +} -- cgit v1.3.1-23-gd82d From 174852de7b331be9ba32c485ffe97d928778b9cc Mon Sep 17 00:00:00 2001 From: angeld55 Date: Wed, 3 Nov 2021 18:25:21 +0200 Subject: sem5 --- Sem. 05_kn/BullsAndCows.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++ Sem. 05_kn/refferences.cpp | 119 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 Sem. 05_kn/BullsAndCows.cpp create mode 100644 Sem. 05_kn/refferences.cpp diff --git a/Sem. 05_kn/BullsAndCows.cpp b/Sem. 05_kn/BullsAndCows.cpp new file mode 100644 index 0000000..1ab2289 --- /dev/null +++ b/Sem. 05_kn/BullsAndCows.cpp @@ -0,0 +1,116 @@ +#include +using namespace std; +// Играта - бикове и крави. + + +const int DIGITS_COUNT = 3; + +int getNumLen(int n) +{ + int count = 0; + while (n != 0) + { + count++; + n /= 10; + } + return count; +} + +bool containsDigit(int n, int digit) +{ + while (n != 0) + { + int lastDigit = n % 10; + + if (digit == lastDigit) + return true; + + n /= 10; + } + return false; +} +bool containsDiffrentDigits(int n) +{ + while (n >= 10) + { + int lastDigit = n % 10; + n /= 10; + + if (containsDigit(n, lastDigit)) + return false; + } + return true; +} + +bool isValid(int n) +{ + return getNumLen(n) == DIGITS_COUNT && containsDiffrentDigits(n); +} + +void userInput(int& toGuess) +{ + do + { + cin >> toGuess; + } while (!isValid(toGuess)); +} + +int getBulls(int toGuess, int myGuess) +{ + int bulls = 0; + while (toGuess != 0) + { + int toGuessLastDigit = toGuess % 10; + int myGuessLastDigit = myGuess % 10; + + if (toGuessLastDigit == myGuessLastDigit) + bulls++; + + toGuess /= 10; + myGuess /= 10; + } + return bulls; +} + +int getCows(int toGuess, int myGuess, int bulls) +{ + int cows = 0; + while (myGuess != 0) + { + int lastDigit = myGuess % 10; + + if (containsDigit(toGuess, lastDigit)) + cows++; + + myGuess /= 10; + } + return cows - bulls; +} + +void getBullsAndCows(int toGuess, int myGuess, int& bulls, int& cows) +{ + bulls = getBulls(toGuess, myGuess); + cows = getCows(toGuess, myGuess, bulls); +} + +int main() +{ + int toGuess; + userInput(toGuess); + + cout << "Try to guess:" << endl; + + int bulls = 0; + int cows = 0; + + while (bulls != DIGITS_COUNT) + { + int myGuess; + userInput(myGuess); + getBullsAndCows(toGuess, myGuess, bulls, cows); + + cout << "Bulls: " << bulls << " " << ", Cows: " << cows << endl; + } + + cout << "Success!" << endl; +} diff --git a/Sem. 05_kn/refferences.cpp b/Sem. 05_kn/refferences.cpp new file mode 100644 index 0000000..47e4fba --- /dev/null +++ b/Sem. 05_kn/refferences.cpp @@ -0,0 +1,119 @@ +#include +using namespace std; + + +int f(int n) +{ + n++; + return n; +} + +// lvalue ("връщане на променлива") +// rvalue ("връщане на константа") + +//Референция - друго име за някоя променлива + +// Пример: +// Напишете функция, която приема цяло число и връща най-голямата и най-малката цифра. + +void getMaxAndMinDigit(int n, int& maxDigit, int& minDigit) +{ + int max = 0; + int min = 9; + + while (n != 0) + { + int lastDigit = n % 10; + + if (lastDigit > max) + max = lastDigit; + + if (lastDigit < min) + min = lastDigit; + + n /= 10; + } + maxDigit = max; + minDigit = min; + +} + +//! + +int& f(int& n) //--няма да върне копие. +{ + n++; + return n; +} + +int main() +{ + int n; + cin >> n; + + int max, min; + + getMaxAndMinDigit(n, max, min); + cout << "Min digit " << min << " " << "max digit " << max << endl; +} + + + + + +#include +using namespace std; + +// lvalue ("връщане на променлива") +// rvalue ("връщане на константа") + +//Референция - друго име за някоя променлива + +//Пример: +// Напишете функция, която приема цяло число и връща най-голямата и най-малката цифра. + +void getMaxAndMinDigit(int n, int& maxDigit, int& minDigit) +{ + int max = 0; + int min = 9; + + while (n != 0) + { + int lastDigit = n % 10; + + if (lastDigit > max) + max = lastDigit; + + if (lastDigit < min) + min = lastDigit; + + n /= 10; + } + maxDigit = max; + minDigit = min; + +} + + +int f1(int& n) //-връщат константа (rvalue) +{ + n++; + return n; +} +int& f2(int& n) //--връщат променлива (lvalue). +{ + n++; + return n; +} +///!!!!!!!!!!! error +int& f3() +{ + int a = 10; + return a; +} +int main() +{ + cout << ++f(); + + +} -- cgit v1.3.1-23-gd82d From 8d5e9200dbc71323b28111c0e229112def9b7c4b Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 18:26:07 +0200 Subject: Update and rename BullsAndCows.cpp to BAndC.cpp --- Sem. 05_kn/BAndC.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++ Sem. 05_kn/BullsAndCows.cpp | 116 -------------------------------------------- 2 files changed, 115 insertions(+), 116 deletions(-) create mode 100644 Sem. 05_kn/BAndC.cpp delete mode 100644 Sem. 05_kn/BullsAndCows.cpp diff --git a/Sem. 05_kn/BAndC.cpp b/Sem. 05_kn/BAndC.cpp new file mode 100644 index 0000000..af55fd0 --- /dev/null +++ b/Sem. 05_kn/BAndC.cpp @@ -0,0 +1,115 @@ +#include +using namespace std; + + +const int DIGITS_COUNT = 3; + +int getNumLen(int n) +{ + int count = 0; + while (n != 0) + { + count++; + n /= 10; + } + return count; +} + +bool containsDigit(int n, int digit) +{ + while (n != 0) + { + int lastDigit = n % 10; + + if (digit == lastDigit) + return true; + + n /= 10; + } + return false; +} +bool containsDiffrentDigits(int n) +{ + while (n >= 10) + { + int lastDigit = n % 10; + n /= 10; + + if (containsDigit(n, lastDigit)) + return false; + } + return true; +} + +bool isValid(int n) +{ + return getNumLen(n) == DIGITS_COUNT && containsDiffrentDigits(n); +} + +void userInput(int& toGuess) +{ + do + { + cin >> toGuess; + } while (!isValid(toGuess)); +} + +int getBulls(int toGuess, int myGuess) +{ + int bulls = 0; + while (toGuess != 0) + { + int toGuessLastDigit = toGuess % 10; + int myGuessLastDigit = myGuess % 10; + + if (toGuessLastDigit == myGuessLastDigit) + bulls++; + + toGuess /= 10; + myGuess /= 10; + } + return bulls; +} + +int getCows(int toGuess, int myGuess, int bulls) +{ + int cows = 0; + while (myGuess != 0) + { + int lastDigit = myGuess % 10; + + if (containsDigit(toGuess, lastDigit)) + cows++; + + myGuess /= 10; + } + return cows - bulls; +} + +void getBullsAndCows(int toGuess, int myGuess, int& bulls, int& cows) +{ + bulls = getBulls(toGuess, myGuess); + cows = getCows(toGuess, myGuess, bulls); +} + +int main() +{ + int toGuess; + userInput(toGuess); + + cout << "Try to guess:" << endl; + + int bulls = 0; + int cows = 0; + + while (bulls != DIGITS_COUNT) + { + int myGuess; + userInput(myGuess); + getBullsAndCows(toGuess, myGuess, bulls, cows); + + cout << "Bulls: " << bulls << " " << ", Cows: " << cows << endl; + } + + cout << "Success!" << endl; +} diff --git a/Sem. 05_kn/BullsAndCows.cpp b/Sem. 05_kn/BullsAndCows.cpp deleted file mode 100644 index 1ab2289..0000000 --- a/Sem. 05_kn/BullsAndCows.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include -using namespace std; -// Играта - бикове и крави. - - -const int DIGITS_COUNT = 3; - -int getNumLen(int n) -{ - int count = 0; - while (n != 0) - { - count++; - n /= 10; - } - return count; -} - -bool containsDigit(int n, int digit) -{ - while (n != 0) - { - int lastDigit = n % 10; - - if (digit == lastDigit) - return true; - - n /= 10; - } - return false; -} -bool containsDiffrentDigits(int n) -{ - while (n >= 10) - { - int lastDigit = n % 10; - n /= 10; - - if (containsDigit(n, lastDigit)) - return false; - } - return true; -} - -bool isValid(int n) -{ - return getNumLen(n) == DIGITS_COUNT && containsDiffrentDigits(n); -} - -void userInput(int& toGuess) -{ - do - { - cin >> toGuess; - } while (!isValid(toGuess)); -} - -int getBulls(int toGuess, int myGuess) -{ - int bulls = 0; - while (toGuess != 0) - { - int toGuessLastDigit = toGuess % 10; - int myGuessLastDigit = myGuess % 10; - - if (toGuessLastDigit == myGuessLastDigit) - bulls++; - - toGuess /= 10; - myGuess /= 10; - } - return bulls; -} - -int getCows(int toGuess, int myGuess, int bulls) -{ - int cows = 0; - while (myGuess != 0) - { - int lastDigit = myGuess % 10; - - if (containsDigit(toGuess, lastDigit)) - cows++; - - myGuess /= 10; - } - return cows - bulls; -} - -void getBullsAndCows(int toGuess, int myGuess, int& bulls, int& cows) -{ - bulls = getBulls(toGuess, myGuess); - cows = getCows(toGuess, myGuess, bulls); -} - -int main() -{ - int toGuess; - userInput(toGuess); - - cout << "Try to guess:" << endl; - - int bulls = 0; - int cows = 0; - - while (bulls != DIGITS_COUNT) - { - int myGuess; - userInput(myGuess); - getBullsAndCows(toGuess, myGuess, bulls, cows); - - cout << "Bulls: " << bulls << " " << ", Cows: " << cows << endl; - } - - cout << "Success!" << endl; -} -- cgit v1.3.1-23-gd82d From d0903680e8c5d1fbbde7b41c3dd2ad58201c2c30 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 18:26:27 +0200 Subject: Update BAndC.cpp --- Sem. 05_kn/BAndC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sem. 05_kn/BAndC.cpp b/Sem. 05_kn/BAndC.cpp index af55fd0..30f8a3d 100644 --- a/Sem. 05_kn/BAndC.cpp +++ b/Sem. 05_kn/BAndC.cpp @@ -2,7 +2,7 @@ using namespace std; -const int DIGITS_COUNT = 3; +const int DIGITS_COUNT = 4; int getNumLen(int n) { -- cgit v1.3.1-23-gd82d From 91c58192153aec6803de90951e2d72b36fcc4e16 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 3 Nov 2021 18:27:18 +0200 Subject: Create draw --- Sem. 05_kn/draw | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Sem. 05_kn/draw diff --git a/Sem. 05_kn/draw b/Sem. 05_kn/draw new file mode 100644 index 0000000..652a201 --- /dev/null +++ b/Sem. 05_kn/draw @@ -0,0 +1,58 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + int spacesCount = 2 * (n - 1) + n + 2 * (n - 1); + int toGuess; + for (int i = 1; i <= n - 1; i++) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount -= 4; + + cout << endl; + + } + + //mid + for (int i = 1; i <= n; i++) + cout << i << " "; + for (int i = 0; i < n; i++) + cout << '-'; + for (int i = n; i >= 1; i--) + cout << " " << i; + cout << endl; + + + //down + spacesCount += 4; + for (int i = n - 1; i >= 0; i--) + { + for (int j = 1; j <= i; j++) + cout << j << " "; + + for (int j = 0; j < spacesCount; j++) + cout << " "; + + for (int j = i; j >= 1; j--) + cout << " " << j; + + spacesCount += 4; + + cout << endl; + + } + + +} -- cgit v1.3.1-23-gd82d