/* Program which will displays the following pattern on the screen: e.g: if user enters height=5,width=11, the output will be: +++++++++++ + + + + + + +++++++++++ + + + + + + +++++++++++ where "height" & "width" is entered by user. */ #include <iostream> //include "iostream" header file #include <iomanip> //include "iomanip" header file using namespace std; int main() { int i, j, height, width; //Declares four int variables do { cout << "Enter Size for pattern:\nEnter Height (an odd number >=3)?\t"; cin >> height; cout << "Enter Width (an odd number >=5)?\t"; cin >> width; } while (height < 3 || width < 5 || height % 2 == 0 || width % 2 == 0); cout << endl; for (i = 1; i <= height; i++) //Control's Height { cout << setw(40 - width / 2); // (Not necessary) for moving Pattern in the centre of console if (i % 2 == 1) //Check's either the row is even or odd for (j = 1; j <= width; j++) //Execute's if line is odd cout << "+"; else for (j = 1; j <= width / 2 + 1; j++) //Execute's if line is odd cout << " +"; cout << "\n"; } return 0; }
This blog is about coding in some commonly used "High Level Languages" like C, C++, Java etc. At first, I will post here basic programs written in C++ language only.
Wednesday, December 17, 2014
C++ Program for displaying particular pattern using "+"
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment