Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Homeworks / homework1.cpp
diff options
context:
space:
mode:
Commit28d28bfb4c8fe765b93745af78ba9f06b334e65a (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-20 21:30:24 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-20 21:30:24 +0200
Filesbb426cb298e53e3aa191fa4002a274547e622631 /Year 1/Programming introduction/Homeworks/homework1.cpp
uni-projects-28d28bfb4c8fe765b93745af78ba9f06b334e65a.tar
uni-projects-28d28bfb4c8fe765b93745af78ba9f06b334e65a.tar.gz
uni-projects-28d28bfb4c8fe765b93745af78ba9f06b334e65a.zip
Parente272d23b4dd1fa776b399be4f838ecb6a9ac56ff (diff)
Solved ex 4
1 files changed, 37 insertions, 1 deletions
-rw-r--r--Year 1/Programming introduction/Homeworks/homework1.cpp38
diff --git a/Year 1/Programming introduction/Homeworks/homework1.cpp b/Year 1/Programming introduction/Homeworks/homework1.cpp
index f4ca9b9..c6832ad 100644
--- a/Year 1/Programming introduction/Homeworks/homework1.cpp
+++ b/Year 1/Programming introduction/Homeworks/homework1.cpp
@@ -69,6 +69,42 @@ void ex2() {
cout << "Шипков мармалад: " << rosehipMarmalades << endl;
}
+/*
+ * Exercise 4
+ */
+
+bool isInteresting(int n) {
+ int lastDigit;
+
+ do {
+ lastDigit = n % 10;
+ n /= 10;
+
+ if ((lastDigit & 1) == ((n % 10) & 1))
+ return false;
+ } while (n != 0);
+
+ return true;
+}
+
+int sumOfInterestingNumsBetween(int a, int b) {
+ int sum = 0;
+
+ for (int i = a; i <= b; i++) {
+ if (isInteresting(i))
+ sum += i;
+ }
+
+ return sum;
+}
+
+void ex4() {
+ int a, b;
+ cin >> a >> b;
+
+ cout << sumOfInterestingNumsBetween(a, b) << endl;
+}
+
int main() {
- ex2();
+ ex4();
}