Questions:
Write a C++ program to draw isosceles triangle using asterisks
Explanation:
This C++ Program is example of nested loop.Below mention code is compiled in Visual Studio 2015 and output snap is attached.. If any problem you feel and want explanation feel free to contact.
Code:
Output:
Related Articles:
C++ Shapes Codes
Write a C++ program to draw isosceles triangle using asterisks
Explanation:
This C++ Program is example of nested loop.Below mention code is compiled in Visual Studio 2015 and output snap is attached.. If any problem you feel and want explanation feel free to contact.
Code:
#include<iostream>
using namespace std;
void main() {
int value;
cout
<< "Enter the
size = ";
cin
>> value;
int space = value;
for (int i = 0; i < value; i++) {
for (int j = space; j > 0; j--) {
cout
<< " ";
}
for (int star = 0; star <= i * 2;
star++) {
cout
<< "*";
}
space--;
cout
<< endl;
}
}
Output:
Related Articles:
C++ Shapes Codes
1 Questions:
// For Rows=4 and column=7
#include
using namespace std;
int main()
{
int i, j;
for (i = 1; i <= 4; i++)
{
for (j = 1; j <= 7; j++)
{
if (j >= 5 - i && j <= 3 + i)
{
cout << "*";
}
else
cout << " ";
}
cout << endl;
}
return 0;
}
//********input from user
#include
using namespace std;
int main()
{
int i, j, r;
cout << "Enter the total no of rows." << endl;
cin >> r;
for (i = 1; i <= r; i++)
{
for (j = 1; j <= (r * 2) - 1; j++)
{
if (j >= (r + 1) - i && j <= (r - 1) + i)
{
cout << "*";
}
else
cout << " ";
}
cout << endl;
}
return 0;
}
Post a Comment