Answer to Question #27802 in C++ for Muhammad Zeeshan

Question #27802
1.Write a C++ Program that generates the following pattern on the screen LMNO LMNOP LMNOPQR LMNOPQRS 2. Write C++ program that generates the following output pattern on the screen ABCDEF ABCDE ABCD ABC AB A
Expert's answer
#include <iostream>
using namespace std;

void pattern_1() {
char start = 'L';
char current;
int length = 4;
for (int i = 0; i < 4; i++) {
current = start;
for (int j = 0; j < length;j++) {
cout <<current++;
}
cout << endl;
length++;
if (i % 2 == 1)
length++;
}
}

void pattern_2() {
char start = 'A';
char current;
int max_length = 6;
int length = 6;
for (int i = 0; i < max_length; i++) {
current = start;
for (int j = 0; j < length;j++) {
cout <<current++;
}
cout << endl;
length--;
}
}

int main()
{
cout << "Pattern 1:" <<endl;
pattern_1();
cout << endl << "Pattern2:" << endl;
pattern_2();

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal