Answer to Question #191183 in C++ for Fuad Endris

Question #191183

Display four patterns using loops) Use nested loops that display the following patterns in four separate programs.  


Pattern A

123456

1 6

1 6

1 6

1 6

123456


Pattern B

1

123

12345

1234567

123456789


Pattern C

3

3 3

3 3 3

3 3

3


Pattern D

1

12

123

1234

12345

123456


1
Expert's answer
2021-05-09T21:48:09-0400
#include <iostream>
using namespace std;
int main(){
    cout<<"Pattern A\n";
    int i = 0;
    for(i = 1; i < 7; i++) cout<<i;
    cout<<endl;
    for(i = 0; i < 4; i++) cout<<1<<" "<<6<<endl;
    for(i = 1; i < 7; i++) cout<<i;
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    cout<<"Pattern B\n";
    int i = 0;
    for(i = 1; i < 6; i++){
        for(int j = 1; j < 2 * i; j++) cout<<j;
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    cout<<"Pattern C\n";
    for(int i = 0; i < 3; i++){
        for(int j = 0; j <= i; j++) cout<<3<<" ";
        cout<<endl;
    }
    for(int i = 2; i > 0; i--){
        for(int j = i; j > 0; j--) cout<<3<<" ";
        cout<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    cout<<"Pattern D\n";
    for(int i = 1; i <= 6; i++){
        for(int j = 1; j <= i; j++) cout<<j;
        cout<<endl;
    }
    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 the first!

Leave a comment