• C

Having trouble getting correct for statement

ok here is my code.  This is probably a simple question.

#include <stdio.h>

int main(void)
{
int h;
int w;
int num;

        printf("\nenter a number: ");
        scanf("%d", &num);

        for(h=1; h<=num; h++)
        {
            printf("\n");

                for(w=1; w <=num; w++)
                {
                        if (w%h != 0  )
                        {
                        printf("*");
                        }
                        else

                        {
                        printf("%d", num);
                        }
                }

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

as you can see I am trying to make a pattern type thing

However i get a pattern that is like this if i were to enter 5

55555
*5*5*
**5**
***5*
****5

but i need it to do this


55555
*5555
**555
***55
****5

I have tryied several this but it will not work.

I also can't come up with patterns that look like these


*****
****5
***55
**555
*5555

and

5****
55***
555**
5555*
55555

and

55555
5555*
555**
55***
5****

any suggestions
thanks
LVL 9
buckeyes33Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_nn_Commented:
>> but i need it to do this

55555
*5555
**555
***55
****5

So, I'll give you just a tiny hint : for each W and H (that makes 25), write down

W | H | result
 1    1     5
 1    2    ...
etc

And try to figure what if() condition you need to use to get the expected result.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_nn_Commented:
Hint for the next "problems" : you may need to write down the values of (num + 1 - W) and (num + 1 - H)
0
buckeyes33Author Commented:
awesome got the first one.  on to the others.   I have a total of 6 patterns i need to make I am currently 3-6. back to work.
0
_nn_Commented:
Last hint : for some of these patterns, I believe you'll have to take a look at the evolution of (W+H) ... ;)
0
buckeyes33Author Commented:
thanks for the suggestions.  When you said to list them that is what really really helped.  I had gotten my first two patterns to come out by just looking at the patterns, but after the could not see how it was supposed to be.  I was able see what connection there was between the number entered and the pattern.  thanks for the help.  Now onto the real meat of the program.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.