Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int x, y, z, num;
- char c;
- cout<<"Insert a number: ";
- cin<<num;
- cout<<"Insert a letter (l, r): ";
- cin<<c;
- if (c == 'l')
- {
- for (x=1; x<=num; x++) //tracks the number of lines
- {
- for (y=1; y<=x; y++) //tracks number of Xs already printed
- {
- cout<<"X";
- }
- cout<<"\n"; //prints newline character in order to start printing next line in the ladder
- }
- }
- else //when c == 'r'
- {
- z = num; //z holds the number of total characters (Xs and whitespace) in a line
- for (x=1; x<=num; x++) //tracks the number of lines
- {
- while (z > x) //i.e while total number of characters in the line is greater than the number of Xs needed
- {
- cout<<" "; //prints spaces in front of the Xs in order to right-align the ladder
- z--;
- }
- for (y=1; y<=x; y++) //tracks number of Xs already printed
- {
- cout<<"X";
- }
- cout<<"\n"; //prints newline character in order to start printing next line in the ladder
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement