diff options
Added todays practice exercises
1 files changed, 127 insertions, 0 deletions
| -rw-r--r-- | Year 1/Programming introduction/Practice-25.10.21.cpp | 127 |
diff --git a/Year 1/Programming introduction/Practice-25.10.21.cpp b/Year 1/Programming introduction/Practice-25.10.21.cpp new file mode 100644 index 0000000..ab96626 --- /dev/null +++ b/Year 1/Programming introduction/Practice-25.10.21.cpp @@ -0,0 +1,127 @@ +#include <iostream> + +using namespace std; + +/* Exercises: + * https://github.com/triffon/ip-2021-22/blob/master/practicum/6/week3/%D0%B7%D0%B0%D0%B4%D0%B0%D1%87%D0%B8%20%D1%82%D1%80%D0%B5%D1%82%D0%B0%20%D1%81%D0%B5%D0%B4%D0%BC%D0%B8%D1%86%D0%B0.pdf +*/ + +void ex0() { + int a; + cin >> a; + + while(a != 0) { + cout << (a % 10); + a /= 10; + } + cout << endl; +} + +void ex1() { + int a; + cin >> a; + + bool isPrime = true; + for(int i = 2; i < a / 2; i++) { // could be improved by doing 6n +- 1 and going up to sqrt(a) + if (a % i == 0) { + isPrime = false; + break; + } + } + cout << ((isPrime) ? "yes" : "no") << endl; +} + +void ex2() { + int a; + cin >> a; + + int digits = (a == 0) ? 1 : 0; + while (a != 0) { + digits++; + a /= 10; + } + cout << digits << endl; +} + +void ex3() { + int a; + cin >> a; + + int b; + while(--a >= 0) { + cin >> b; + cout << b; + } + cout << endl; +} + +void ex4() { + for (int i = 100, digitSum; i < 1000; i++) { // could probably be optimized + digitSum = i % 10 + (i / 10) % 10 + i / 100; + if (digitSum > 9 && digitSum < 99) + cout << i << endl; + } +} + +void ex5() { + int n; + cin >> n; + + if (n < 2) cout << n << endl; + else { + int sum = 1, current; + for (int i = 2, j = 0; i <= n; i++, j = current) { + current = sum; + sum += j; + j = current; + } + cout << sum << endl; + } +} + +void ex6() { + int n; + cin >> n; + + for(int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) + cout << "*"; + cout << endl; + } +} + +void ex7() { + int n; + cin >> n; + if (n % 2 == 0) n++; + + for (int i = n, starsPerRow; i >= -1 * n; i-=2) { + starsPerRow = (i < 0) ? i * -1 : i; + + for (int j = (n - starsPerRow) / 2; j > 0; j--) + cout << " "; + for (int j = starsPerRow; j > 0; j--) + cout << "*"; + + cout << endl; + } +} + +void ex8() { + int hour1, hour2; + cin >> hour1 >> hour2; + + if (hour2 < hour1) { + int tmp = hour2; + hour2 = hour1; + hour1 = tmp; + } + for (int i = hour1 + 1; i < hour2; i++) { + cout << i << endl; + if (i % 100 == 59) i += 40; + } +} + +int main() { + ex8(); +} |
