Question

4 3 2 1 2 3 4 6 5 4 3 2 1 2 3 4 5 7 6 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 6 7 5.20 (Display four patterns using loops) Use nested loops that display the following patterns in four separate programs: Pattern A Pattern B Pattern C Pattern D 1 2 3 4 5 6 1 2 3 4 5 6 1 2 1 2 3 4 5 1 2 3 4 5 1 2 3 4 1 2 3 4 3 2 1 1 2 3 4 3 2 1 1 2 3 1 2 3 4 1 2 3 1 2 5 4 3 2 1 1 2 1 2 3 4 5 6 5 4 3 2 1 1 2 3 4 5 6 21 (Display numbers in pyramid pattern) Write a nested for loop that displays the a following output
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PATTERN A:

#include<stdio.h>

int main(){
  
   int i,j;
  
   for(i=0;i<6;i++){
       for(j=0;j<6;j++){
           if(j<=i){
               printf("%d ",j+1);
           }
       }
       printf("\n");
   }
  
}

OUTPUT:

PATTERN B AND D:

#include<stdio.h>

int main(){
  
   int i,j;
  
   for(i=0;i<6;i++){
       for(j=0;j<6-i;j++){
      
               printf("%d ",j+1);
          
       }
       printf("\n");
   }
  
}

OUTPUT:

PATTERN C:

#include<stdio.h>

int main(){
  
   int i,j;
  
   for(i=0;i<6;i++){
       int k=i+1;
       for(j=0;j<6;j++){
           if(j>=6-i-1){
              
               printf("%d ",k);
               k--;
           }else{
               printf(" ");
           }
       }
       printf("\n");
   }
  
}

OUTPUT:

PYRAMID PATTERN:

#include<stdio.h>

int main(){
  
   int i,j;
  
   for(i=0;i<7;i++){
       int k=i+1;
       int l=2;
       for(j=0;j<13;j++){
           if(j>=7-i-1){
               if(k!=0){
                   printf("%d ",k);
               k--;
               }else if(l<=i+1){
                   printf("%d ",l);
               l++;
               }
              
           }else{
               printf(" ");
           }
       }
       printf("\n");
   }
  
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Use nested loops that display the following patterns in four separate programs: (Display numbers in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Display for patterns using loops In python language!!!!!!!! including comments!!!! Use nested loops that display the...

    Display for patterns using loops In python language!!!!!!!! including comments!!!! Use nested loops that display the following patterns in four separate programs:

  • C++ any help is appreciated Program Pattern#2: Write a program that uses nested loop or for...

    C++ any help is appreciated Program Pattern#2: Write a program that uses nested loop or for statements to display Pattern A below, followed by an empty line and then another set of loops that displays Pattern B. Once again no setw implementation is allowed here but you must use nested loop or for statements with proper indentation to generate these patterns. Use meaningful variable identifier names, good prompting messages and appropriate comments for each loop segment as well as other...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • Create A MultiplicationTable program using nested for loops which will display a multiplication table for the...

    Create A MultiplicationTable program using nested for loops which will display a multiplication table for the hexadecimal numbers 1 - F. Nested for Hint: if you use the System.out.printf method with a format specifier "%X" it will display an integer value in hexadecimal format.

  • Write a program Using loops to display the following patterns – (i) ********** (ii) ******************** (iii)...

    Write a program Using loops to display the following patterns – (i) ********** (ii) ******************** (iii) * ** *** **** ***** ****** ******* ******** ********* ********** (iv) * ** *** **** ***** ****** ******* ******** ********* ********** *********** ************ ************* ************** *************** **************** ***************** ****************** ******************* ******************** (v) ********** ********* ******** ******* ****** ***** **** *** ** * (vi) ******************** ******************* ****************** ***************** **************** *************** ************** ************* ************ *********** ********** ********* ******** ******* ****** ***** **** *** ** * Your...

  • Write a function (NOT a complete program) that displays the following picture. Use nested for loops...

    Write a function (NOT a complete program) that displays the following picture. Use nested for loops inside of the program. ||#|@|#|(a) | # | @ # | @ #|(a) | # | @ You do not need to ask the user for input and can assume that there are only 6 columns

  • 1. Create the following patterns in the terminal using nested for loops (each pattern is 9...

    1. Create the following patterns in the terminal using nested for loops (each pattern is 9 x 9 fields) Your Code should have a main function which asks the user to select which pattern to print (A, B, C, or D) The rest of the code should be in one function called printPattern, which does not return anything (is void ), but takes one letter as parameter (from the user selection). This letter determines which pattern the function prints to...

  • AT46.1: Nested loops: Indent text HALLENGE 461: Nested loops: Indent text Print numbers 0,1,2 userNum as...

    AT46.1: Nested loops: Indent text HALLENGE 461: Nested loops: Indent text Print numbers 0,1,2 userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex userNum-3 prints 3 int noin(void){ 6 int 1- Your solution goes here 1e return...

  • Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print...

    Computer Science I home> 4 8 Nested loops Feedback | 48.1 Nested loops Indent text Print numbers 0, 1,2userNum as shown, with each number indented by that number of spaces For each printed line, print the leading spaces, then the number, and then a newline Hint. Use i and j as loop variables (initialize i and j explicitly). Note. Avoid any other spaces like spaces after the printed number Ex userNum-3 prints

  • write code in C++ make it print just like like the above image. 5.12 (Drawing Patterns...

    write code in C++ make it print just like like the above image. 5.12 (Drawing Patterns with Nested for Loops) Write a program that uses for statements to print 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 (this causes the asterisks to print side by side). [Hint: The last two patterns require that each line begin with an appropriate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT