Replies To: asterisks printed by only one printf and one for loop in the form

Re: asterisks printed by only one printf and one for loop in the form

Posted 05 October 2012 - 11:33 AM

Please provide what you have started so we can actually help. Just giving us your assignment (in an incredibly annoyingly large font) doesn't allow us to help you with what you are having trouble with.

Re: asterisks printed by only one printf and one for loop in the form

Posted 05 October 2012 - 11:46 AM

no2pencil, on 05 October 2012 - 11:33 AM, said:

Please provide what you have started so we can actually help. Just giving us your assignment (in an incredibly annoyingly large font) doesn't allow us to help you with what you are having trouble with.

Oh I'm really sorry about the font it's just that i wanted to be noticed as I need this urgent. Here is what I have made with nested loops. Now this works fine but I actually need to use only one for loop. That is the only confusing part. Is it really possible in C ? and if yes then how?

Re: asterisks printed by only one printf and one for loop in the form

I think that you have been mesmerized by nested for loops that you forget that printf() can take more than one character.

for(int i = 0; i < 3; i++)
printf("aychdogg");

So what happens when your replace you alias with some other string that somehow includes 5 asterisks?

Do you really think I would ask such a thing if it was that easy to just write 5 asterisks myself and then loop them thrice. I know how to do that but the limitations I have been given are confusing because I don't know if it is really possible.

Let me make myself more clear like this

1. Only one printf in the form printf ("*") is allowed which should be printed 5 times like *****
2. Only one for loop should loop this thrice so that I get this pattern

Re: asterisks printed by only one printf and one for loop in the form

Do you really think I would ask such a thing if it was that easy to just write 5 asterisks myself and then loop them thrice.

A little bit of advice my friend : tone it down.

You open the topic with the idea that louder gets you faster results. It will actually cause members to just ignore the topic.
You didn't print your code, we had to ask for it. Waste of our time, & a waste of your time waiting.
A member with years of experience in your field is trying to help you with an elementary project, & your tone reads that he's an idiot.

You are doing all of the things you shouldn't do, to receive good, quality help. What you are doing is what causes members to think "forget this guy", & not offer any help at all. You must remember we are under no obligation to assist you.

Re: asterisks printed by only one printf and one for loop in the form

I need to write a C code in which I am to use only one printf and only one for loop. That's it. No nested for loops or other loops.

It was only on post #5 that you elaborated that the printf() also has restriction on what the format string could be:

aychdogg, on 05 October 2012 - 12:13 PM, said:

1. Only one printf in the form printf ("*") is allowed

Interestingly in post #5 you also stated:

aychdogg, on 05 October 2012 - 12:13 PM, said:

2. Only one for loop should loop this thrice

So does this mean that this restriction goes away?

aychdogg, on 05 October 2012 - 11:32 AM, said:

No nested for loops or other loops.

Hey thanks for your time and well I'm sorry for the wrong beggining I'm just new to this so I hope you understand. Anyways the person who gave this project said that he wants me to use only one printf ("*") and only one for loop to get this output

It prints three asterisks just fine but now I need these five asterisks to be repeated thrice like the output i gave above. I could use nested for loop for this or a number of other solutions but the restriction of using only one for loop has put me into trouble. I hope you can get me out of this.

Re: asterisks printed by only one printf and one for loop in the form

Posted 05 October 2012 - 12:52 PM

I would add a conditional if/else & if your count is within five, print a new line '\n'. Thus you print fifteen asterisks in your for loops, & within the loop count to five, print the '\n', & reset your counter.

Re: asterisks printed by only one printf and one for loop in the form

Posted 05 October 2012 - 12:59 PM

no2pencil, on 05 October 2012 - 12:52 PM, said:

I would add a conditional if/else & if your count is within five, print a new line '\n'. Thus you print fifteen asterisks in your for loops, & within the loop count to five, print the '\n', & reset your counter.

Or loop 3 times, & use two counters within the loop.

hhmm well yes if/else conditionals work fine too. Can you give me a little snippet example without using the if/else? I don't know if im logically correct on this but like combining two for loops into one somehow?

Re: asterisks printed by only one printf and one for loop in the form

Posted 05 October 2012 - 01:12 PM

Actually, the part that has me puzzled is how he is going to print out the '\n' at the end of each line without using printf(), unless he is also allowed to use printf("\n") or allowed to use putchar('\n'). But then if he is allowed to use putchar(), he can even do the assignment/challenge without even using printf(), and use putchar() all the way.

Re: asterisks printed by only one printf and one for loop in the form

Posted 05 October 2012 - 01:14 PM

No I do php so I know it can be done and all but I don't have a clue how to do it in C. I think the teacher only wants us to confirm that it can't be done like this as a practice. I don't know. I'm confused.