fork download
  1. //Nathan Dominguez CSC5 Chapter 5, P. 298, #23
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Display Two Patterns
  6.  * _____________________________________________________________________________
  7.  * This program uses loops to display a 2 types of pyramids. The first loops
  8.  * creates Pattern A. The second loop creates the inverse of Pattern A labeled
  9.  * Pattern B.
  10.  * _____________________________________________________________________________
  11.  * INPUT
  12.  * lengthPyramid : Variable for pyramid size
  13.  * display : Variable of display character
  14.  * countRowPyramid1 : Variable for lines in first pyramid
  15.  * countRowPyramid2 : Variable for lines in second pyramid
  16.  * lineLoop : Variable to loop lines
  17.  *
  18.  * OUTPUT
  19.  * display : Display character which is +.
  20.  *
  21.  ******************************************************************************/
  22. #include <iostream>
  23.  
  24. using namespace std;
  25.  
  26. int main()
  27. {
  28. // Declare Variables
  29. int lengthPyramid = 10; // Variable to hold size of the Pyramid
  30. char display = '+'; // Display Character of '+' for Pyramid
  31.  
  32. cout << "Pattern A:" << endl;
  33. //
  34. //Loop for first pattern
  35. for(int countRowPyramid1 = 0; countRowPyramid1 <= lengthPyramid; countRowPyramid1++)
  36. {
  37. cout << "\t";
  38. for(int lineLoop = 0; lineLoop < countRowPyramid1; lineLoop++)
  39. {
  40. cout << display;
  41. }
  42. cout <<endl;
  43. }
  44. //
  45. //Loop for second pattern
  46. cout << endl << "Pattern B:" << endl << endl;
  47. for(int countRowPyramid2 = 10; countRowPyramid2 >= 0; countRowPyramid2--)
  48. {
  49. cout << "\t";
  50. lengthPyramid = countRowPyramid2;
  51. for(; lengthPyramid > 0; lengthPyramid--)
  52. {
  53. cout << display;
  54. }
  55. cout <<endl;
  56. }
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Pattern A:
	
	+
	++
	+++
	++++
	+++++
	++++++
	+++++++
	++++++++
	+++++++++
	++++++++++

Pattern B:

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