Write a C++ program that displays this isosceles triangle formed by a character chosen by the user. The height of the triangle (which is the number of lines, at least equal to 2) is given by the user too. For example, with a * character, and for 5 lines, the program will output the following triangle :
*
***
*****
*******
*********
Use for loops in this problem.
Source code in C++
#include <iostream>
using namespace std;
int main()
{
int i, j, k=1 ,line;
char ch;
cout<<"Enter the character to be print\n";
cin>> ch;
cout<<"Enter the number of lines to be print\n";
cin>>line;
cout<<"Traingle : \n";
for(i=0; i<line; i++)
{
for(j=0; j<k; j++)
{
cout<<ch;
}
k=k+2;
cout<<"\n";
}
return 0;
}
Output Screen Shot:
Thank you............
Get Answers For Free
Most questions answered within 1 hours.