C++ program to print two parallel triangles using for loop




Source Code :

#include "iostream"
using namespace std;

int main()
{
cout << "Enter Odd Integer to Print parallel triangles :";
int n;
cin >> n;
int mid = (n + 1) / 2;
int c = 1;

for (int i = 1; i <= n; i++) {

if (i > mid) {
c -= 2;
}

for (int j = n; j >= c; j--) {
cout << "*";
}

if (i < mid) {
c += 2;
}

cout << endl;
}

system("PAUSE");
    return 0;
}


No comments:

Post a Comment