English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

1
2 1
3 2 1

2007-08-14 07:11:20 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

Think about how you can use a for loop to do this.

2007-08-14 07:27:36 · answer #1 · answered by christnp 7 · 0 0

Probably the simplest (one line):

void main() { printf( "1\n2 1\n3 2 1\n" ); }

But of course using a nested loop would be far more flexible.

Use a variable such as x and loop it from 1 to 3, i.e. for (x = 1; x <= 3; x++ )
Then use another variable such as y and loop it from x to 1 using a negative increment, i.e. for (y = x; y >= 1; y--)
Print the result with a space after it, i.e. printf("%d ", y)
outside of the inner loop, print a carriage return, i.e. printf("\n")

Hopefully that's enough hints to get you there.

2007-08-14 07:40:57 · answer #2 · answered by TreyJ 3 · 0 0

Are you telling me that you can't figure out how to print out this screen output based on the person's answer to your last question?

Just incase you can't find the link to your last question's answers, here is the link:

Now modify that code or learn to do your own homework. This is such a basic example that even a lazy programmer should be able to find examples online if they didn't want to crack their C programming book.

If you want to make this more sophisticated, yes you can use christnp's suggestion to use looping. In fact it would make the most sense to do that if you believe your teacher is going to as you to quickly change to another iteration.

2007-08-14 07:28:43 · answer #3 · answered by Jim Maryland 7 · 1 0

ohh.. you may desire to count selection what number selection you have created. in simple terms tack one static variable and increment it in for loop on the tip of this methodology you may printf static variable to comprehend what number variable you have created..

2016-12-13 07:27:54 · answer #4 · answered by ? 3 · 0 0

fedest.com, questions and answers