Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 03 / 03. Remove_Middle_Digits.cpp
diff options
context:
space:
mode:
Commit3f402620ecd071fb467b108036ac08ed48c5f929 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 21:18:33 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-03 21:18:33 +0200
Files4c18cc86afc1c951f02768bfd9dc1b4e2ab8df99 /Year 1/Programming introduction/Solutions Sem. 03/03. Remove_Middle_Digits.cpp
uni-projects-3f402620ecd071fb467b108036ac08ed48c5f929.tar
uni-projects-3f402620ecd071fb467b108036ac08ed48c5f929.tar.gz
uni-projects-3f402620ecd071fb467b108036ac08ed48c5f929.zip
Parentdf27afaa9a5bb3d3a168b57c8c407d25e553f13f (diff)
Updated some styling and formatting
1 files changed, 3 insertions, 4 deletions
-rw-r--r--Year 1/Programming introduction/Solutions Sem. 03/03. Remove_Middle_Digits.cpp7
diff --git a/Year 1/Programming introduction/Solutions Sem. 03/03. Remove_Middle_Digits.cpp b/Year 1/Programming introduction/Solutions Sem. 03/03. Remove_Middle_Digits.cpp
index c22a028..7e7be68 100644
--- a/Year 1/Programming introduction/Solutions Sem. 03/03. Remove_Middle_Digits.cpp
+++ b/Year 1/Programming introduction/Solutions Sem. 03/03. Remove_Middle_Digits.cpp
@@ -11,13 +11,12 @@ int main()
for (int i = n; i != 0; i /= 10)
digits++;
- int digitsToTakeFromEachEnd = digits / 2 + (digits % 2 - 1);
- int tenToTheHalf = 1; // ten to the power of digits to take from each end
+ int tenToTheHalf = 1; // 10 to the power of digits to take from each end (calculated in the loop below)
- for (int i = 0; i < digitsToTakeFromEachEnd; i++)
+ for (int endDigits = digits / 2 + (digits % 2 - 1); endDigits > 0; endDigits--)
tenToTheHalf *= 10;
- int tenToTheMiddle = (digits % 2 == 0) ? 100 : 10; // ten to the power of digits to remove from the middle
+ int tenToTheMiddle = (digits % 2 == 0) ? 100 : 10; // 10 to the power of digits to remove from the middle
int resultNumber = (n % tenToTheHalf) + (n / tenToTheHalf / tenToTheMiddle) * tenToTheHalf;