Tuesday 21 July 2020

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.]

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()
{
forint 1<= 10i++ )

{
forint 1<= 10j++)
{
cout << (<= "*" " " ;
}c
out << endl;
}
//for pause
system("PAUSE";
return 0;
}


b)

#include < iostream>
using namespace std;
int main()
{
forint 10>= 1i‐‐ )
{
forint 1<= 10j++)
{
cout << (<= "*" " " ;
}

cout << endl;
}

system("PAUSE";
return 0;
}


c)

#include < iostream>
using namespace std;
int main()
{
forint 100i‐‐ )
{
forint 100j‐‐)
{
cout << (<= "*" " " ;
}c
out << endl;
}
//for pause
system("PAUSE";
return 0;
}

d)

#include < iostream>
using namespace std;
int main()
{
forint 1<= 10i++ )
{
forint 10>= 1j‐‐)
{
cout << (<= "*" " " ;
}c
out << endl;
}
//for pause
system("PAUSE";
return 0;
}

No comments:

Post a Comment