Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: How to arrange some numbers (http://www.velocityreviews.com/forums/t958706-re-how-to-arrange-some-numbers.html)

Eric Sosman 03-15-2013 05:30 PM

Re: How to arrange some numbers
 
On 3/15/2013 12:02 PM, paskali wrote:
> Hi, a simple question:
> i want to arrange some int numbers; i want to store them
> in an array and then print them on the screen.
>
> Look below:
>
> int numbers[10], arranged[10], i;
> puts("Insert 10 int numbers");
> for(i = 0; i <= 9; i ++, scanf("%d", &numbers[i]));
> ?
> for(i = 0; i <= 9; i ++, printf("/n%d", arranged[i]));
>
> I insert: 10 7 45 678 0 34 6 1 4 3
> I should see on the screen: 0 1 3 4 6 7 10 34 45 678
> Simple. Help me to replace question mark.


First fix the bug in the line before it, and the
similar bug in the line after it.

Then make your own attempt at filling in the question
mark. If you get into trouble, show what you've tried and
describe what went wrong.

--
Eric Sosman
esosman@comcast-dot-net.invalid

Eric Sosman 03-15-2013 08:33 PM

Re: How to arrange some numbers
 
On 3/15/2013 4:07 PM, paskali wrote:
> Eric Sosman <esosman@comcast-dot-net.invalid> wrote:
>
>> On 3/15/2013 12:02 PM, paskali wrote:
>>> Hi, a simple question:
>>> i want to arrange some int numbers; i want to store them
>>> in an array and then print them on the screen.
>>>
>>> Look below:
>>>
>>> int numbers[10], arranged[10], i;
>>> puts("Insert 10 int numbers");
>>> for(i = 0; i <= 9; i ++, scanf("%d", &numbers[i]));
>>> ?
>>> for(i = 0; i <= 9; i ++, printf("/n%d", arranged[i]));
>>>
>>> I insert: 10 7 45 678 0 34 6 1 4 3
>>> I should see on the screen: 0 1 3 4 6 7 10 34 45 678
>>> Simple. Help me to replace question mark.

>>
>> First fix the bug in the line before it, and the
>> similar bug in the line after it.
>>
>> Then make your own attempt at filling in the question
>> mark. If you get into trouble, show what you've tried and
>> describe what went wrong.
>>

> "/n" apart, some time i use an old compiler in that do work.


Oddly enough, I hadn't even noticed the "/n". (Sigh.)

> However you intend:
>
> int numbers[10], i, arranged[10];
> puts("Insert 10 int numbers");
> for(i = 0; i <= 9; i ++) scanf("%d", &numbers[i]);
> ?
> for(i = 0; i <= 9; i ++) printf("\n%d", numbers[i]);


This fixes the bug(s) I mentioned: You've eliminated the
off-by-one error. Also, I see that you are now printing from
the same array you read into instead of from a different array,
so I guess you now intend to rearrange `numbers' in place
instead of moving them to `arranged'.

> However i tried without success.


If you'll show what you tried and describe how it failed,
perhaps we can help you figure out why it didn't succeed.

--
Eric Sosman
esosman@comcast-dot-net.invalid

osmium 03-15-2013 08:35 PM

Re: How to arrange some numbers
 
"paskali" wrote:

> Eric Sosman <esosman@comcast-dot-net.invalid> wrote:
>
>> On 3/15/2013 12:02 PM, paskali wrote:
>> > Hi, a simple question:
>> > i want to arrange some int numbers; i want to store them
>> > in an array and then print them on the screen.
>> >
>> > Look below:
>> >
>> > int numbers[10], arranged[10], i;
>> > puts("Insert 10 int numbers");
>> > for(i = 0; i <= 9; i ++, scanf("%d", &numbers[i]));
>> > ?
>> > for(i = 0; i <= 9; i ++, printf("/n%d", arranged[i]));
>> >
>> > I insert: 10 7 45 678 0 34 6 1 4 3
>> > I should see on the screen: 0 1 3 4 6 7 10 34 45 678
>> > Simple. Help me to replace question mark.

>>
>> First fix the bug in the line before it, and the
>> similar bug in the line after it.
>>
>> Then make your own attempt at filling in the question
>> mark. If you get into trouble, show what you've tried and
>> describe what went wrong.
>>

> "/n" apart, some time i use an old compiler in that do work.
>
> However you intend:
>
> int numbers[10], i, arranged[10];
> puts("Insert 10 int numbers");
> for(i = 0; i <= 9; i ++) scanf("%d", &numbers[i]);
> ?
> for(i = 0; i <= 9; i ++) printf("\n%d", numbers[i]);
>
> However i tried without success.


It is difficult to determine your meaning. Replace the question mark with
*your* bubble sort and post the result. That is, if you have a problem.
Your second code fragment compiles and runs OK for me.




All times are GMT. The time now is 07:11 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.