Write a program in C++ to print given pattern: **** ### ** # | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Write a program in C++ to print given pattern: **** ### ** #

#include <iostream> using namespace std; int main() { int rows; cout << "Enter number of rows: "; cin >> rows; for(int i = rows; i >= 1; --i) { for(int j = 1; j <= i; ++j) { if (j == 1) System.out.print(i); else if (i % 2 == 0) System.out.print('#'); else System.out.print('*'); } System.out.println(); }

27th Mar 2023, 6:23 PM
Simran Samantra
Simran Samantra - avatar
3 Answers
+ 3
Yes. Try it and discover that you can do it, too. If you have trouble solving it, then show what you tried and explain where you are having difficulty.
27th Mar 2023, 6:34 PM
Brian
Brian - avatar
+ 3
Simran Samantra 1. You mixed C++ and Java syntax. Use `cout` for printing outputs. 2. Missing } to close main() function body. 3. No need to check <j> == 1, remove that block and make the check for <i> % 2 == 0 becomes the `if` block. Leave the `else` block as is, and use `cout`instead of System.out.print().
27th Mar 2023, 6:56 PM
Ipang
+ 2
Let me see your code, I'll see what I can do to help. Attach link to your code bit inside original post Description above ...
27th Mar 2023, 6:33 PM
Ipang