#include <iostream>
using namespace std;
void printpattern(int pattern_type, int pattern_size);//function call
int main()
{
int pattern_type;
int pattern_size;
char ans;
ans=='y';//this makes it loop until the uses enters a different character
while (ans=='y' || ans == 'Y')
{
cout << "Please enter pattern type.\n";
cin >> pattern_type;
cout << "Please enter a pattern size.\n";
cin >> pattern_size;
printpattern(pattern_type, pattern_size);
cout << "Please enter Y or y to continue. Enter any other character to exit the program.\n";
cin >> ans;
}
return 0;
}
void printpattern(int pattern_type, int pattern_size)
{
if(pattern_size > 10 || pattern_size < 1)
{
cout << "Pattern size should be between (1-10)\n";
return;
}
switch (pattern_type)
{
case 1:
for (int i=0; i < pattern_size; i++)
{
for (int j=0; j < pattern_size; j++)
if (i==j)
cout << "\t" << "$";
else
cout << ' ';
cout << endl;
}
case 2:
for (int i=0; i < pattern_size; i++)
{
for (int j=0; j < pattern_size; j++)
if (j <= i)
cout << "$";
else
cout << ' ';
cout << endl;
}
break;
case 3:
for (int i=0; i < pattern_size; i++)
{
for (int j=0; j < pattern_size; j++)
if (j >= i)
cout << "$";
else
cout << ' ';
cout << endl;
}
break;
default:
cout << "Pattern type should be between (1-3).\n";
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgcHJpbnRwYXR0ZXJuKGludCBwYXR0ZXJuX3R5cGUsIGludCBwYXR0ZXJuX3NpemUpOy8vZnVuY3Rpb24gY2FsbAoKaW50IG1haW4oKQp7CiAgICAgICAgaW50IHBhdHRlcm5fdHlwZTsKICAgICAgICBpbnQgcGF0dGVybl9zaXplOwogICAgICAgIGNoYXIgYW5zOwoKICAgICAgICBhbnM9PSd5JzsvL3RoaXMgbWFrZXMgaXQgbG9vcCB1bnRpbCB0aGUgdXNlcyBlbnRlcnMgYSBkaWZmZXJlbnQgY2hhcmFjdGVyCgogICAgICAgIHdoaWxlIChhbnM9PSd5JyB8fCBhbnMgPT0gJ1knKQogICAgICAgIHsKICAgICAgICAgICAgICAgIGNvdXQgPDwgIlBsZWFzZSBlbnRlciBwYXR0ZXJuIHR5cGUuXG4iOwogICAgICAgICAgICAgICAgY2luID4+IHBhdHRlcm5fdHlwZTsKICAgICAgICAgICAgICAgIGNvdXQgPDwgIlBsZWFzZSBlbnRlciBhIHBhdHRlcm4gc2l6ZS5cbiI7CiAgICAgICAgICAgICAgICBjaW4gPj4gcGF0dGVybl9zaXplOwoKICAgICAgICAgICAgICAgIHByaW50cGF0dGVybihwYXR0ZXJuX3R5cGUsIHBhdHRlcm5fc2l6ZSk7CgogY291dCA8PCAiUGxlYXNlIGVudGVyIFkgb3IgeSB0byBjb250aW51ZS4gRW50ZXIgYW55IG90aGVyIGNoYXJhY3RlciB0byBleGl0IHRoZSBwcm9ncmFtLlxuIjsKICAgICAgICAgICAgICAgIGNpbiA+PiBhbnM7CiAgICAgICAgfQoKcmV0dXJuIDA7Cn0KCgp2b2lkIHByaW50cGF0dGVybihpbnQgcGF0dGVybl90eXBlLCBpbnQgcGF0dGVybl9zaXplKQp7CgogICAgICAgIGlmKHBhdHRlcm5fc2l6ZSA+IDEwIHx8IHBhdHRlcm5fc2l6ZSA8IDEpCiAgICAgICAgewogICAgICAgICAgICAgICAgY291dCA8PCAiUGF0dGVybiBzaXplIHNob3VsZCBiZSBiZXR3ZWVuICgxLTEwKVxuIjsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CgogICAgICAgIHN3aXRjaCAocGF0dGVybl90eXBlKQogICAgICAgIHsKCiAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgZm9yIChpbnQgaT0wOyBpIDwgcGF0dGVybl9zaXplOyBpKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAoaW50IGo9MDsgaiA8IHBhdHRlcm5fc2l6ZTsgaisrKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpPT1qKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY291dCA8PCAiXHQiIDw8ICIkIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICcgJzsKICAgICAgICAgICAgICAgICAgICAgICAgY291dCA8PCBlbmRsOwogICAgICAgICAgICAgICAgfQogICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIGZvciAoaW50IGk9MDsgaSA8IHBhdHRlcm5fc2l6ZTsgaSsrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGludCBqPTA7IGogPCBwYXR0ZXJuX3NpemU7IGorKykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaiA8PSBpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY291dCA8PCAiJCI7CiAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICcgJzsKCiAgICAgICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgZW5kbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBmb3IgKGludCBpPTA7IGkgPCBwYXR0ZXJuX3NpemU7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgaj0wOyBqIDwgcGF0dGVybl9zaXplOyBqKyspCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGogPj0gaSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgIiQiOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgJyAnOwogICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKCiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIGNvdXQgPDwgIlBhdHRlcm4gdHlwZSBzaG91bGQgYmUgYmV0d2VlbiAoMS0zKS5cbiI7CiAgICAgICAgfQp9