Im c This program outputs a downwards facing arrow composed
Solution
Please follow the code and comments for description :
CODE :
#include <iostream> // required header files
#include <string>
using namespace std;
int main() // driver method
{
int arrowBaseHeight = 0; // required initialisations
int arrowBaseWidth = 0;
int arrowHeadWidth = 0;
int i = 0;
cout << \"Please Enter the desired arrow base height: \"; // prompt to enter the data
cin >> arrowBaseHeight; // getting the data
cout << \"Please Enter the desired arrow base width: \"; // prompt to enter the data
cin >> arrowBaseWidth; // getting the data
while (arrowHeadWidth <= arrowBaseWidth) { // checking for the condition
cout << \"Please Enter the desired arrow head width: \"; // prompt to enter the data
cin >> arrowHeadWidth; // getting the data
}
string ast = \"\"; // ast will contain how many asterisk we want for the base width;
int tempBaseHeight = arrowBaseWidth; // temporary variable
for (int x = 1; x <= arrowBaseHeight; x++) //iterating to form the base width of the arrow
{
for(int y = 1; y <= tempBaseHeight; y++)
{
cout << \"*\"; // printing the asterisks
}
cout << endl;
}
for (i = 1; i <= arrowBaseHeight; i++)
{
cout << ast; //Printing the base width
}
int tempHeadWidth = arrowHeadWidth;
for (int y = 1; y <= arrowHeadWidth; y++)
{
for(int z = tempHeadWidth; z > 0; z--) // iterating to print the number of asterisks we need per line in the arrowHead
{
cout << \"*\";
}
tempHeadWidth -= 1; // decrementing the value to run the code till the head width
cout << endl; // it makes a new line to keep adding more asterisks for the next row
}
}
OUTPUT :
CASE 1 :
Enter arrow base height: 5
Enter arrow base width: 2
Enter arrow head width: 4
**
**
**
**
**
****
***
**
*
CASE 2 :
Enter arrow base height: 5
Enter arrow base width: 3
Enter arrow head width: 1
Enter arrow head width: 2
Enter arrow head width: 3
Enter arrow head width: 4
***
***
***
***
***
****
***
**
*
Hope this is helpful.

