Answer to Question #27802 in C++ for Muhammad Zeeshan
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
1
2013-04-08T11:00:13-0400
#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!
Learn more about our help with Assignments:
C++
Comments
Leave a comment