Write a C++ programthat reads in the side of a square and prints out a pattern on$

symbols representing thatsquare. The program should work for side sizes between

2 and 10. For example, ifa size of 4 is entered, the following output should be

produced:

$$

$$

$$

Respuesta :

Answer:

#include<iostream>

using namespace std;

//main function

int main(){

   //initialize the variables

   int side;

   //print the message

   cout<<"Please enter the side of square: ";

   cin>>side;  //read the vale and store in the variable.

   // for loop

   for(int i=1;i<=side;i++){  //lop for rows

       for(int j=1;j<=side;j++){   //loop for column

           cout<<"$";  //print the '*'

       }

       cout<<endl;

   }

}

Explanation:

Create the main function and declare the variable side.

print the message on the screen for the user and then store value enter by the user on the variable side.

take the nested for loop for print the pattern.

nested for loop means, loop inside another loop it is used for print the pattern having rows and columns.

the first loop updates the row number and the second the loop print the character '

Otras preguntas

in the column-wise.

in the code,

if i = 1, for loop check the condition 1 <= 5 if the value of side is assume 5.

condition is true and the program moves to the second for loop and starts to print the character '

Otras preguntas

five times after that, print the new line.

then, the above process repeat for different rows and finally, we get the pattern in square shape.

Otras preguntas

17. a) Using the same axes; shade the region P of all points (x,y) which satisfy the following four inequalities simultaneously: i) y ≥ 0 ii) x + 2y ≤ 4 iii) -x
Spruce budworms are a major pest that defoliates balsam fir. They are preyed upon by birds. A model for the per capita predation rate is given by f(N)= (aN)/(k²
Where does Aquifex fit on a tree? Choose the number location in the tree for your organism, Aquifex. 1 4 5 8 9 3 7. Let's place your organism on a basic phyloge
In relation to the MSP432E401Y board, what core processor is used and define its registers (purpose and number of bits)? [4] a) ARM Cortex-M0, 32 bits b) ARM Co
Why are market prices useful to a financial manager when performing a cost-benefit analysis?a) Because they reflect the equilibrium between supply and demandb)
In Windows, files that are moved to the recycle bin are permanently deleted. a) True b) False
The fundamental basis for requiring a detailed supplier cost analysis as opposed to simply a price analysis is when:a. You are procuring a Leverage spend itemb.
The sum of two numbers is 2490.if 6.5%of one number is equal to 8.5% of the other .then the numbers are
Who assigns only graduates of the Naval School of Aviation Safety who are naval aviators or naval flight officers to the primary duty of ASO in manned aircraft
State which of the following chemical reactions will take place or not, giving a suitable reason for each. A) Reaction 1 - Yes, due to B) Reaction 2 - No, beca