Question

In: Computer Science

Use nested for loops to generate the following patterns: C++ ***** ***** ***** (no space between...

Use nested for loops to generate the following patterns: C++

*****

*****

*****

(no space between rows of asterisks)

*

**

***

****

*****

(Again, no empty lines between rows)

*

**

***

**

*

(no lines between rows)

Last one, let the user pick the pattern by specifying the number of rows and columns.

Solutions

Expert Solution


#include <iostream>

using namespace std;

int main() {
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
cout<<"*";
cout<<endl;
}
}

#include <iostream>

using namespace std;

int main() {
for(int i=0;i<=5;i++)
{
for(int j=0;j<i;j++)
cout<<"*";
cout<<endl;
}
}

#include <iostream>
using namespace std;
int main()
{
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(int i=0;i<rows;i++)
{
for(int j=0;j<i;j++)
cout<<"*";
cout<<endl;
}
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
cout<<"*";
}
cout<<endl;
}
  
return 0;
}


Related Solutions

Use nested for loops statements to generate the following output. (Java) -----1 ---22 --333 4444 Ignore...
Use nested for loops statements to generate the following output. (Java) -----1 ---22 --333 4444 Ignore the dashes formatting wouldnt allow for extra spaces behind the numbers
In C 1- Use nested for loops to create an addition lookup table. Fill in an...
In C 1- Use nested for loops to create an addition lookup table. Fill in an array and print out the following table showing the sum of the row and column numbers 0-9. 0 1 2 3 4.. <- column numbers 1 2 3 4 5.. 2 3 4 5 6.. <- These nos. = Row + Column 3 4 5 6 7.. <- for example 7 = 3 + 4 4 5 6 7 8.. ... ^Row numbers 2-...
Print the following two patterns using nested loops. Using java. Pattern 1 13579 13579 13579 13579...
Print the following two patterns using nested loops. Using java. Pattern 1 13579 13579 13579 13579 Pattern 2 #####1 ### #12 ###123 ##1234 #12345
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2...
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2 #####1 ####12 ###123 ##1234 #12345
C++ In this lab you will be using nested for loops to print out stars in...
C++ In this lab you will be using nested for loops to print out stars in a Diamond pattern such as this: * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** *** * For example , if number of rows=8 then the above pattern is derived. You are to take the input for the number of lines(rows) from a file named "input_diamond" and output the pattern into both the terminal and an output file named "output_diamond".
IN C++ Write a program that uses nested loops to collect data and calculate the average...
IN C++ Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the ­­program should display the...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number...
Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops,...
Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops, if loops, while loops, arrays and conditional execution, as well as creating an image of the game board. The list below must be considered in the code. - Selecting a word from a dictionary (a text file) - Reading a single letter from the user - Building a character array showing the letters matched so far - Keeping count of the number of guessed...
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through...
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through the array. Each pass compares successive pairs of elements. If a pair is in increasing order (or the values are equal), the sorting procedure leaves the values as they are. If a pair is in decreasing order, the sorting procedure swaps their values in the array.  The first pass compares the first two elements of the array and swaps their values if necessary....
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT