Question

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 sections in the body of your program.

Note: Each triangle has exactly seven rows and the width of each row is an odd number. The triangles have appropriate labels displayed.  

Pattern A

+
+++
+++++
+++++++
+++++++++
+++++++++++
+++++++++++++

Pattern B

+++++++++++++
+++++++++++
+++++++++
+++++++
+++++
+++
+

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream> 
using namespace std; 
int main() 
{ 
   int n = 7, count = 1;
   cout<<"Pattern A"<<endl;
   for(int i = 0;i<n;i++){
      for(int j = 0;j<count;j++){
         cout<<'+';
      }  
      count+=2;
      cout<<endl;
   }
   
   cout<<"Pattern B"<<endl;
   for(int i = 0;i<n;i++){
      count -= 2;
      for(int j = 0;j<count;j++){
         cout<<'+';
      }  
      cout<<endl;
   }
  
    return 0; 
} 

Add a comment
Know the answer?
Add Answer to:
C++ any help is appreciated Program Pattern#2: Write a program that uses nested loop or for...
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
  • Loops: Write a program that uses a loop to diplay Pattern A below

    Loops: Write a program that uses a loop to diplay Pattern A below, followed by another loop that displays Pattern B. 

  • Write a Python program (using a nested loop) to print out the following pattern (there is...

    Write a Python program (using a nested loop) to print out the following pattern (there is a space between the numbers next to each other). 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1

  • Turtle Graphics with nested loop: Write a turtle graphics python program repeat_squares.py that uses nested loops...

    Turtle Graphics with nested loop: Write a turtle graphics python program repeat_squares.py that uses nested loops to draw 100 squares, to create this design: Turtle-squares.png starting with the smallest square in the bottom right-hand corner. Start at position (-4,4). At each step increase the length of each side by 4 pixels. Draw 100 squares. Please submit with an animation speed of 0 and the turtle hidden turtle.hideturtle()

  • Write them in python IDLE ***** 5. Average Rainfall Write a program that uses nested loops...

    Write them in python IDLE ***** 5. Average Rainfall 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 for the number of years. The outer loop will iterate once for each year. The inner loop will iterate twelve 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,...

  • Write a program that uses nested loops to collect data and calculate the average rainfall over...

    Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should prompt the user for the number of years. Be sure to ask for each months average rainfall for each year. The outer loop will iterate once for each year while the inner loop will iterate 12 times(one time per month) prompting for the months average rainfall on each iteration. Display the number of months, the total inches...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Write a java program that uses a loop to input, from the user not using gui,...

    Write a java program that uses a loop to input, from the user not using gui, a collection of values that are the number of steps taken each day for a sequence of days and stores those amounts in an array. the array length should be 31, The user is not required to enter 31 values. the program determines and displays the largest number of steps for a single day, the smallest number of steps for a single day and...

  • Help with c# code Write a program that generates the following sequence using for loop 2,...

    Help with c# code Write a program that generates the following sequence using for loop 2, 3 , 6, 11, 18, 27, … , 102 Using two nested for loops, generate the following 10 20 30 40 50 60 20 30 40 50 60 30 40 50 60 40 50 60 50 60 60

  • write a java program that does the following Part one Use a For loop to compute...

    write a java program that does the following Part one Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic (Nested loops: Indent text) so that the...

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