I have a little problem. I would like to draw triangle in rectangle thanks "Loop For" and I have code about rectangle and triangle, but I can't add this. Can anyone help ?
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int n;
cout <<"Write n: ";
cin >> n;
for (int rows=0; rows!=n;rows++)
{
Sleep(200);
for (int cols=0; cols!=n; cols++)
{
if (rows==0 || rows==n-1 || cols==0 || cols==n-1)
{
cout <<"*";
}
else
{
cout <<" ";
}
}
cout << endl;
}
/* Drawing triangle:
for (int i=0; i<n; i++)
{
for (int j=0; j<n-i; j++)
{
cout <<" ";
}
for (int k=0; k<2*i-1; k++)
{
cout <<"*";
}
cout << endl;
}
*/
return 0;
}
No responses yet.