Question

In: Computer Science

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

Solutions

Expert Solution

Pattern 1:

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int count=1;                   //initializing count as 1
    for(int i=1;i<=4;i++){        //numbers of rows
        for(int j=1;j<=5;j++){   //number of columns 
            cout<<count;        //printing digits in row
            count=count+2;     //adding 2 
        }
            cout<<endl;       //go to new line
            count=1;         //make count again 1 for 2nd row
    }
}

Pattern 2:

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int count=1;                //initializing count as 1
    for(int i=1;i<=5;i++){      //for loop for row
        for(int j=1;j<=6;j++){  //for loop for column
            
             if(j<=6-i){        
            cout<<"#";
            }
            else
            {
            cout<<count++;        
            }   
        }
            cout<<endl;
            count=1;     
    }
    
}

Related Solutions

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
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".
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.
create a function in matlab that sums two m x n matrices using nested loops, then...
create a function in matlab that sums two m x n matrices using nested loops, then returns result into a new matrix. Use nesed for loops to add matrices piece by piece. Basically means, dont program simply A+B Function should perform error check to make sure both matrices have same number of rows/ columns.
C++ Code Using all for loops 1. Print 5 lines with 1 asterisk per line 2....
C++ Code Using all for loops 1. Print 5 lines with 1 asterisk per line 2. Print 5 asterisk on 1 line. Endl at the end of the line. 3. Ask for a positive # and print that many asterik on the next line. 4. Using 2 for loops one inside of another that only prints 1 asterik, print a hill shaped triangle: Ex( Input a number a: 4 * ** *** **** 5. Change the for statements to print...
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...
JAVA Write nested while loop that will print out this pattern, based upon a number entered...
JAVA Write nested while loop that will print out this pattern, based upon a number entered by the user. User enters 4: 1234 1234 1234 1234 User enters 2: 12 12
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345...
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345 1) the source code (.java file), and 2) the screenshot of running results of each question.
Using Matlab: Using nested for loops (other methods are not allowed), write a function which takes...
Using Matlab: Using nested for loops (other methods are not allowed), write a function which takes as input a matrix, and as output returns true if at least one entry in the matrix is strictly greater than 8 and returns false otherwise.
In this exercise we will practice using nested loops. You will write s program that prompts...
In this exercise we will practice using nested loops. You will write s program that prompts the user to enter an integer between 1 and 9 and displays a pyramid of numbers, as shown in the example below. The program must validate the input given by the user and make sure that: if the user enters a non-integer the program issues an error message and requests the user provides a valid input. if the user does not enter a number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT