How to become good in solving a pattern program?

Thread Starter

Dadu@

Joined Feb 4, 2022
155
I want to become proficent in solving a pattern program in c langauge. I am just starting, are there any special trick to get into this ? I want to go from easy to difficult , which pattern should I start with?

This is my template for pattern
C:
#include <stdio.h>

int main ()
{
     int i, j = 0;
    
    for ( i = 0; i < 10; i++)
    {
        for ( j = 0; j < 10; j++)
        {

            printf ("*");
        }
        printf("\n");   
        
    }
    
    return 0;
}
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
 

KeithWalker

Joined Jul 10, 2017
3,607
I want to become proficent in solving a pattern program in c langauge. I am just starting, are there any special trick to get into this ? I want to go from easy to difficult , which pattern should I start with?
Proficiency is a combination of knowledge and experience so the best way to become proficient with any subject is to read about it, practice with it and experiment with it.
Have fun.
 

Thread Starter

Dadu@

Joined Feb 4, 2022
155
How to print Full Pyramid of *
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
I have seen others code on internet but I don't understand their code.

Here is my attempt to solve. I am having trouble inside inner loop. How to do it step by step ?

C:
#include <stdio.h>

int main ()
{
     int i, j = 0;
    
    for ( i = 0; i < 5; i++)
    {
        for ( j = 0; j < 9; j++)
        {
                        
            printf ("*", j);
        }
        printf("\n");   
        
    }
    return 0;
}
 

Ya’akov

Joined Jan 27, 2019
10,235
You need an inner loop that has the current value of the outer loop as its limit. So, if you want 9 * as your biggest line, the outer loop will be to 9, and the inner loop will take the value of the iterator of the outer loop for it's upper limit.

Once the outer loop reaches 9, it terminates and so no more inner looping.
 

Thread Starter

Dadu@

Joined Feb 4, 2022
155
You need an inner loop that has the current value of the outer loop as its limit. So, if you want 9 * as your biggest line, the outer loop will be to 9, and the inner loop will take the value of the iterator of the outer loop for it's upper limit.

Once the outer loop reaches 9, it terminates and so no more inner looping.
I'm stuck I don't know how to proceed. I understand how inner loop and outer loop works.
 

Ya’akov

Joined Jan 27, 2019
10,235
I'm stuck I don't know how to proceed. I understand how inner loop and outer loop works.
You understand but you don't know what to do? How does that work?
You said you saw the code others had written but you don't understand it. I explained it and you said you already know that.

What is it that you don't understand? Everything you need is in the code others wrote and in my explanation.

What do you mean, "step-by-step"?
 
Top