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 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Sem. 03/solutions/exercise 09 - rightmost pyramid.cpp (limited to 'Sem. 03/solutions/exercise 09 - 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; +} -- cgit v1.3.1-26-gb76a