5.15 (Triangle-Printing Program) Write an application that displays the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks (*) should be printed by a single statement of the form cout << '*'; which causes the asterisks to print side by side. A statement of the form cout << '\n'; can be used to move to the next line. A statement of the form cout << ' '; can be used to display a space for the last two patterns. There should be no other output statements in the program. [Hint: The last two patterns require that each line begin with an appropriate number of blank spaces.]
Solution:a)
#include < iostream>
using namespace std;
int main()
{
for( int i = 1; i <= 10; i++ )
{
for( int j = 1; j <= 10; j++)
{
cout << (j <= i ? "*" : " " ) ;
}c
out << endl;
}
//for pause
system("PAUSE") ;
return 0;
}
b)
#include < iostream>
using namespace std;
int main()
{
for( int i = 10; i >= 1; i‐‐ )
{
for( int j = 1; j <= 10; j++)
{
cout << (j <= i ? "*" : " " ) ;
}
cout << endl;
}
system("PAUSE") ;
return 0;
}
c)
#include < iostream>
using namespace std;
int main()
{
for( int i = 10; i > 0; i‐‐ )
{
for( int j = 10; j > 0; j‐‐)
{
cout << (j <= i ? "*" : " " ) ;
}c
out << endl;
}
//for pause
system("PAUSE") ;
return 0;
}
d)
#include < iostream>
using namespace std;
int main()