Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit0b5c76b5757bca63a20b72fa959f74747b465d2b (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2020-10-23 14:34:45 +0300
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2020-10-23 14:34:45 +0300
Filesa481998df73b82207febb8b1aaab04549c2dd441
Introduction_to_programming_FMI-0b5c76b5757bca63a20b72fa959f74747b465d2b.tar
Introduction_to_programming_FMI-0b5c76b5757bca63a20b72fa959f74747b465d2b.tar.gz
Introduction_to_programming_FMI-0b5c76b5757bca63a20b72fa959f74747b465d2b.zip
Parent96e731c9bf4aaf3979740620441cf98c6fe3b46d (diff)
added examples for sem 3
8 files changed, 204 insertions, 1 deletions
-rw-r--r--README.md3
-rw-r--r--Sem. 3/Contains5.cpp32
-rw-r--r--Sem. 3/DevidersCount_PrimalityCheck.cpp29
-rw-r--r--Sem. 3/GCD_solution1.cpp32
-rw-r--r--Sem. 3/GCD_solution2.cpp35
-rw-r--r--Sem. 3/GCD_solution3_Eucid.cpp25
-rw-r--r--Sem. 3/PrintEvenNumbers.cpp27
-rw-r--r--Sem. 3/SumOfDigits.cpp22
diff --git a/README.md b/README.md
index 77eb559..9bc86fa 100644
--- a/README.md
+++ b/README.md
@@ -2,4 +2,5 @@
- **Тема 1 (09.10.2020) :** Променливи. Типове променливи. Оператори. Преобразуване между типове.
-.- **Тема 1 (16.10.2020) :** Приоритет на операторите. Асоциативност. Условни провеки (if, switch)
+ - **Тема 2 (16.10.2020) :** Приоритет на операторите. Асоциативност. Условни провеки (if, switch)
+ - **Тема 3 (23.10.2020) :** Жизнен цикъл на променливите. Оператори за цикъл(while, for). Оператор break. Задачи \ No newline at end of file
diff --git a/Sem. 3/Contains5.cpp b/Sem. 3/Contains5.cpp
new file mode 100644
index 0000000..78d13f0
--- /dev/null
+++ b/Sem. 3/Contains5.cpp
@@ -0,0 +1,32 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ int n;
+ cin >> n;
+
+ bool foundFive = false;
+ while (n != 0)
+ {
+ int lastDigit = n % 10;
+ if (lastDigit == 5)
+ {
+ foundFive = true;
+ break;
+ }
+ n /= 10;
+ }
+
+ if (foundFive)
+ {
+ cout << "yes";
+ }
+ else
+ {
+ cout << "no";
+ }
+
+
+} \ No newline at end of file
diff --git a/Sem. 3/DevidersCount_PrimalityCheck.cpp b/Sem. 3/DevidersCount_PrimalityCheck.cpp
new file mode 100644
index 0000000..7584722
--- /dev/null
+++ b/Sem. 3/DevidersCount_PrimalityCheck.cpp
@@ -0,0 +1,29 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ unsigned int n; //allways positive int
+ cin >> n;
+
+ int divCount = 0;
+
+ for (int i = 1; i <= n; i++)
+ {
+ if (n%i == 0)
+ divCount++;
+ }
+ cout << divCount;
+ if (divCount == 2)
+ {
+ cout << "Prime";
+ }
+ else
+ {
+ cout << "Not a prime";
+ }
+
+
+
+} \ No newline at end of file
diff --git a/Sem. 3/GCD_solution1.cpp b/Sem. 3/GCD_solution1.cpp
new file mode 100644
index 0000000..58ea35b
--- /dev/null
+++ b/Sem. 3/GCD_solution1.cpp
@@ -0,0 +1,32 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ int n, k;
+
+ cin >> n >> k;
+
+ if (n < k) //swap
+ {
+ int temp = n;
+ n = k;
+ k = temp;
+ }
+
+ int devider = 1;
+ int result;
+ while (devider <= k)
+ {
+ if (n % devider == 0 && k % devider == 0)
+ {
+ result = devider;
+ }
+ devider++;
+ }
+
+ cout << result;
+
+
+} \ No newline at end of file
diff --git a/Sem. 3/GCD_solution2.cpp b/Sem. 3/GCD_solution2.cpp
new file mode 100644
index 0000000..ba06c89
--- /dev/null
+++ b/Sem. 3/GCD_solution2.cpp
@@ -0,0 +1,35 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ int n, k;
+
+ cin >> n >> k;
+
+ if (n < k) //swap
+ {
+ int temp = n;
+ n = k;
+ k = temp;
+
+ }
+ int devider = k;
+ bool foundSolution = false;
+
+
+ while (!foundSolution)
+ {
+ if (n % devider == 0 && k % devider == 0)
+ foundSolution = true;
+ else
+ devider--;
+
+
+ }
+ cout << devider;
+
+
+
+} \ No newline at end of file
diff --git a/Sem. 3/GCD_solution3_Eucid.cpp b/Sem. 3/GCD_solution3_Eucid.cpp
new file mode 100644
index 0000000..f190a90
--- /dev/null
+++ b/Sem. 3/GCD_solution3_Eucid.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ int n, k;
+
+ cin >> n >> k;
+
+ if (n < k) //swap
+ {
+ int temp = n;
+ n = k;
+ k = temp;
+ }
+
+ while (k != 0)
+ {
+ int div = n % k;
+ n = k;
+ k = div;
+ }
+ cout << n << endl;
+} \ No newline at end of file
diff --git a/Sem. 3/PrintEvenNumbers.cpp b/Sem. 3/PrintEvenNumbers.cpp
new file mode 100644
index 0000000..e9a2231
--- /dev/null
+++ b/Sem. 3/PrintEvenNumbers.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ int n;
+ cin >> n;
+
+ int j = 0;
+ while (j <= n)
+ {
+ cout << j << endl;
+ j += 2;
+ }
+
+ //Here the variable j is reachable!
+
+
+ for (int i = 0; i <=n; i++)
+ {
+ cout << i << endl;
+ }
+ // Here the variable i is NOT reachable.
+
+
+} \ No newline at end of file
diff --git a/Sem. 3/SumOfDigits.cpp b/Sem. 3/SumOfDigits.cpp
new file mode 100644
index 0000000..6777a42
--- /dev/null
+++ b/Sem. 3/SumOfDigits.cpp
@@ -0,0 +1,22 @@
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ int n;
+ cin >> n;
+
+ int digitSum = 0;
+
+ while (n != 0)
+ {
+ int lastDigit = n % 10; //extracts last digit
+ digitSum += lastDigit; //adds it to the sum
+ n /= 10; //removes last digit
+ }
+
+ cout << digitSum;
+
+
+} \ No newline at end of file