Click here to Skip to main content
15,887,313 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Write a program to skip two elements after the occurrence of an odd number and print the array elements in the following pattern

* *
*
*
*
* * * *
*
*
*
*
*
* * * * * * *


What I have tried:

did not understand the question
Posted
Updated 8-Aug-22 9:40am
v2
Comments
Patrice T 8-Aug-22 15:39pm    
Did you rephrase the original requirement ?
If so, give us the original requirement, and show your work so far.
Greg Utas 9-Aug-22 8:01am    
I don't understand the question either. Either you left out some information or it is poorly worded. I'm guessing that there is an example (an array) that is supposed to produce the output that you've shown.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you don't understand the question, then you need to discuss that with your tutor: we have no access to the array you mention, or any idea what rules the pattern is supposed to follow as a result.

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
 
C
puts("* *\n*\n*\n*\n* * * *\n*\n*\n*\n*\n*\n* * * * * * *\n");
 
Share this answer
 
Comments
jeron1 8-Aug-22 15:20pm    
Very pragmatic, nice! :-)
CPallini 25-Sep-23 2:02am    
5.
Count the number of stars on each line. Now work out how you can automate that with one or more loops
 
Share this answer
 
I didn't understand the first part of the question. But I can solve the pattern printing using loops as follows:

int i = 1, j = 2, k = 1;

while (k <= 3) {
    for (int x = 0; x < i; x++) {
        if (x==(i-1)){
            for (int y = 0; y < j; y++) {
                printf("* ");
            }
        }
        else{
            printf("*");
        }
        printf("\n");
    }
    i += 3;
    j += 2;
    k++;
}
 
Share this answer
 
Comments
Richard Deeming 25-Sep-23 7:36am    
Doing someone's homework for them is never a good idea.

Especially not 13 months after they were due to hand it in.

And even more especially not when the answer you're posting is for a completely different question! 🤦‍♂️

Stick to answering new questions, and make sure you understand the question fully before answering.

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