gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
write code in c++ to create an equilateral triangle. get the number of rows for the…
- User
write code in c++ to create an equilateral triangle. get the number of rows for the triangle from receiving input by the user.
- Assistant
Here is the code in C++ to create an equilateral triangle based on the number of rows entered by the user:
#include <iostream> using namespace std; int main() { int numRows; // Get the number of rows for the triangle from the user cout << "Enter the number of rows for the equilateral triangle: "; cin >> numRows; cout << endl; // Print equilateral triangle for (int i = 1; i <= numRows; i++) { // Print spaces before each row for (int j = 1; j <= numRows - i; j++) { cout << " "; } // Print stars in each row for (int k = 1; k <= (2 * i) - 1; k++) { cout << "*"; } // Move to the next line after each row cout << endl; } return 0; }This code prompts the user to enter the number of rows for the equilateral triangle. It then uses nested loops to print the required number of spaces and stars to form an equilateral triangle.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.