Created
October 23, 2024 12:28
-
-
Save juanfal/293413e7b0d602ce082d8c1dda67040e to your computer and use it in GitHub Desktop.
triangle of numbers non-consecutive function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// l04e01.trianglenum.cpp | |
// juanfc 2024-10-23 | |
// | |
// | |
// \Ej Build a procedure that receives from the main() program the height of the next numerical triangle and prints it: | |
// Height? 11 | |
// 1 | |
// 232 | |
// 34543 | |
// 4567654 | |
// 567898765 | |
// 67890109876 | |
// 7890123210987 | |
// 890123454321098 | |
// 90123456765432109 | |
// 0123456789876543210 | |
// 123456789010987654321 | |
// HINT To avoid more than one digit outputs, print n % 10 Start n in 1. | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
void tri(int h); | |
tri(11); | |
return 0; | |
} | |
void tri(int h) | |
{ | |
for (int lin = 1; lin <= h; ++lin) { | |
for (int i = 0; i < h-lin; ++i) | |
cout << ' '; | |
for (int i = lin; i < 2*lin-1; ++i) | |
cout << i % 10; | |
for (int i = 2*lin-1; i >= lin; --i) | |
cout << i % 10; | |
cout << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment