# format a pattern output

posted 5 years ago

- 0

hello all, I wrote a simple program that display a pattern of numbers

You can see the output through running as it has spaces before numbers and the page doesn't allow spaces to be

displayed before numbers.

well, all i need in this program is that i want to insert space between numbers

and the pattern remain as it is.

I'd be grateful if you give me any notes about my program

thanks..............

You can see the output through running as it has spaces before numbers and the page doesn't allow spaces to be

displayed before numbers.

well, all i need in this program is that i want to insert space between numbers

and the pattern remain as it is.

I'd be grateful if you give me any notes about my program

thanks..............

I Hear I Forget, I See I Remember, I Do I Understand.

posted 5 years ago

- 0

so...after you print a number, print a space.

Note that since each 'number' will now take two positions (one for the digit, and one for the space) you may need to print two spaces instead of one on your line 11, depending on what you want the actual output to look like.

also, this will have problems if your '6' changes to something larger than '9'.

Note that since each 'number' will now take two positions (one for the digit, and one for the space) you may need to print two spaces instead of one on your line 11, depending on what you want the actual output to look like.

also, this will have problems if your '6' changes to something larger than '9'.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

posted 5 years ago
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

- 0

sure...but it's not trivial.

part of the problem is that you have to know how much space you need before you print your first line. I.e., if the biggest number is one digit, you only need one space. if the biggest is 2 digits, you need two spaces for the first few numbers, then only one.

if your biggest number is 3 digits, you'll need to pad three spaces for the first few, then two spaces for the next 90, then 1 space...

etc.

Of course, I'm just guessing here, since I don't know what you are REALLY trying to do. What is your actual goal/what do your actual specs say?

part of the problem is that you have to know how much space you need before you print your first line. I.e., if the biggest number is one digit, you only need one space. if the biggest is 2 digits, you need two spaces for the first few numbers, then only one.

if your biggest number is 3 digits, you'll need to pad three spaces for the first few, then two spaces for the next 90, then 1 space...

etc.

Of course, I'm just guessing here, since I don't know what you are REALLY trying to do. What is your actual goal/what do your actual specs say?

Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |