Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:53
Show Gist options
  • Save pinglunliao/90f2a9bb2d859f0e3900 to your computer and use it in GitHub Desktop.
Save pinglunliao/90f2a9bb2d859f0e3900 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void prtTriangle(short a, int f)
{
short start = -a + 1;
short end = a - 1;
for( int times = 0; times < f - 1; times++ )
{
for(short n = start; n <= end; n++)
{
int out = a - abs(n);
for(int k = abs(n); k < a; k++)
cout << out;
cout << endl;
}
cout << endl;
}
for(short n = start; n <= end; n++)
{
int out = a - abs(n);
for(int k = abs(n); k < a; k++)
cout << out;
cout << endl;
}
}
int main()
{
int n, a, f;
cin >> n;
while( cin >> a >> f )
{
prtTriangle(a, f);
n--;
if( n <= 0 )
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment