Sunday, 12 February 2017

How to print the all the patterns?


#include<iostream>
using namespace std;
void triangle(int k);
void triangle2(int k);
void triangle3(int k);
void triangle4(int k);
void piramid(int k);
void piramidu(int k);
int main()
{
        int k;
cout << "Enter the numbers of the rows " << endl;
cin >> k;
triangle(k);
cout << endl;
triangle2(k);
cout << endl;
triangle3(k);
cout << endl;
triangle4(k);
cout << endl;
piramid(k);
cout << endl;
piramidu(k);
cout << endl;
system("pause");
return 0;
}
void triangle(int k) {
for (int i = 0; i < k; ++i) {
for (int j = 0; j < i; ++j) {
cout << "*";
}
cout << endl;
}

}
void triangle2(int k) {
for (int i = 0; i < k; ++i) {
for (int j = k-i; j > 0; --j) {
cout << "*";
}
cout << endl;
}
}
void triangle3(int k) {
for (int i = 0; i < k; ++i) {
for (int j = k-i; j > 0; --j) {
cout << " ";

}
for (int m = 0; m < i; ++m) {
cout << "*";
}

cout << endl;
}
}
void triangle4(int k) {
for (int i = 0; i < k; ++i) {
for (int j = 0; j < i; ++j) {
cout << " ";
}
for (int m = k-i; m > 0; --m) {
cout << "*";
}
cout << endl;
}


}
void piramid(int k) {
for (int i = 0; i < k; ++i) {
for (int j = k - i; j > 0; --j) {
cout << " ";
}
for (int m = -1; m < 2 * i; ++m) {
cout << "*";
}
cout << endl;
}
}
void piramidu(int k) {
for (int i = 0; i < k; ++i) {
for (int j = 0; j < i; ++j) {
cout << " ";
}
for (int m = 1; m < 2 * k - 2 * i; ++m) {
cout << "*";
}

cout << endl;
}

}

No comments:

Post a Comment