Solved

Having trouble getting correct for statement

Posted on 2003-10-26
5
188 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:buckeyes33
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
_nn_ earned 250 total points
ID: 9623759
>> 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
 
LVL 16

Expert Comment

by:_nn_
ID: 9623764
Hint for the next "problems" : you may need to write down the values of (num + 1 - W) and (num + 1 - H)
0
 
LVL 9

Author Comment

by:buckeyes33
ID: 9623885
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
 
LVL 16

Expert Comment

by:_nn_
ID: 9624051
Last hint : for some of these patterns, I believe you'll have to take a look at the evolution of (W+H) ... ;)
0
 
LVL 9

Author Comment

by:buckeyes33
ID: 9624244
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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
rhel6 C system() call to zip to archive has problems 25 241
Adjust Mfcapp 29 166
convert char array to number in c 5 85
Using popen() and gunzip() to open file in HTTPServer 6 59
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question