+ 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(); }
3 Antworten
+ 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.
+ 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().
+ 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 ...