Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
How to print this pattern
* * * *
 * * * 
* * * * 
 * * *


What I have tried:

Yap I tried to much solve this problem but i can't solve please help me to solve this problem
Posted
Updated 24-Mar-23 3:10am
v8
Comments
Patrice T 23-Mar-23 6:42am    
Show your work so far.
show actual output.
Ralf Meier 23-Mar-23 8:01am    
For future questions :
"Help me to solve this problem" is not a qualified description or a title with sense.
Perhaps you think about that ...

Alternating four stars, with three ones?
Are you kidding?
Use Google: search for "basic console I/O with C#".
 
Share this answer
 

The trick with these sort of patterns where there is particular character separated by a space is to keep track of the number of characters printed and to use the modulus operator to decide whether to print the character or the space. Things are much more simple if the lines are of the same length as you can use the modulus operator to decide when to start a new line. In your example, the lines appear to be different lengths but, by adding a space to the end of the 3 star lines, the pattern looks the same but now every line is the same length. What is more, the pattern becomes a 28 character series of alternating * and space characters with a line break on every 7th character. So it can be solved using a single for loop and a couple of modulus operations

 
Share this answer
 
This is not a difficult problem. You alternate between printing four stars with three spaces, and four spaces with three stars. So a couple of simple loops will do it.

So think about what each loop needs to do and try it yourself.
 
Share this answer
 
v2
Write a method that takes a single integer parameter and which prints that number of stars.
Test it, fix it, make sure it works for every value it might be given.
When it does, call it inside a loop with alternating numbers: 4, then 3, then 4 again, and so on.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900