# what is wrong!

Discussion in 'C Programming' started by John, Jan 8, 2005.

1. ### JohnGuest

Hi all,
I wrote the code to get the following output:
1 2 3 4 5 6 7 8 9 10
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
2 1 3 4 5 6 7 8 9 10
1 3 2 4 5 6 7 8 9 10
3 2 4 1 5 6 7 8 9 10
2 4 1 5 3 6 7 8 9 10
4 1 5 3 6 2 7 8 9 10
1 5 3 6 2 7 4 8 9 10
5 3 6 2 7 4 8 1 9 10
3 6 2 7 4 8 1 9 5 10
6 2 7 4 8 1 9 5 10 3

but,the output received from the code is different.
there is some mistake and I got confusion on.if you
know some better advice and correction to my code,

tanx a lot!

the code wrote by me is as below:

#include<stdio.h>

int main(){
int a[10][10];
int i,j,k,temp;

printf("input the integer\n");
for(i=0;i<10;i++)
scanf("%d",&a[0]);

printf("put the integer 9times\n");
for(i=0;i<9;i++){
scanf("%d",&temp);

a[i+1][temp-1] = a[0];

for(j=0;j<temp-1;j++)
a[i+1][j] = a[j+1];
for(j=temp;j<10;j++)
a[i+1][j] = a[j];

}

for(i=0;i<10;i++){
for(j=0;j<10;j++){
printf("%d ",a[j]);
}
printf("\n");
return 0;
}
}

--
John

John, Jan 8, 2005

2. ### Mike WahlerGuest

"John" <> wrote in message
news:...
> Hi all,
> I wrote the code to get the following output:
> 1 2 3 4 5 6 7 8 9 10
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 1 2 3 4 5 6 7 8 9 10
> 2 1 3 4 5 6 7 8 9 10
> 1 3 2 4 5 6 7 8 9 10
> 3 2 4 1 5 6 7 8 9 10
> 2 4 1 5 3 6 7 8 9 10
> 4 1 5 3 6 2 7 8 9 10
> 1 5 3 6 2 7 4 8 9 10
> 5 3 6 2 7 4 8 1 9 10
> 3 6 2 7 4 8 1 9 5 10
> 6 2 7 4 8 1 9 5 10 3
>
>
> but,the output received from the code is different.
> there is some mistake and I got confusion on.if you
> know some better advice and correction to my code,
> please show it.

Please describe exactly what the program is supposed to
do. I won't try to figure out what the 'pattern' is
supposed to be.

The way you've phrased it, my solution would be to
simply 'hard code' those lines and output them

e.g.:

puts("1 2 3 4 5 6 7 8 9 10");

etc.

(but I doubt that's what's wanted).

Also please learn to indent your code.

-Mike

Mike Wahler, Jan 8, 2005

3. ### JohnGuest

Dear Mike,

I try to declare a two dimensional array with a size 10 by 10 at
first.after that I am
going to read the integers into a[0][0] to a[0]]9] .after that,I am
going to repeat the
insertion specified by an integer sequence about 9 times, and store the
results from
a[1] to a[9].
at the final,I try to print the array same as I pointed to my first
post as an out put.

thanks

John, Jan 8, 2005
4. ### Nick AustinGuest

On 8 Jan 2005 07:20:31 -0800, "John" <> wrote:

One mistake I notice is that the return statement is inside
the loop instead of following it:

>for(i=0;i<10;i++){
>for(j=0;j<10;j++){
>printf("%d ",a[j]);
>}
> printf("\n");
> return 0;
> }

Nick.

Nick Austin, Jan 8, 2005
5. ### Keith ThompsonGuest

"Mike Wahler" <> writes:
[snip]
> Also please learn to indent your code.
>
> -Mike

The OP probably did indent his code. There's a serious bug (several,
actually) in the new groups.google.com posting interface.

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Keith Thompson, Jan 8, 2005
6. ### Mike WahlerGuest

"Keith Thompson" <> wrote in message
news:...
> "Mike Wahler" <> writes:
> [snip]
> > Also please learn to indent your code.
> >
> > -Mike

>
> The OP probably did indent his code. There's a serious bug (several,
> actually) in the new groups.google.com posting interface.

This is why we always advise folks not to post code
with tabs -- convert them to spaces first. Or is
google mangling those too?

-Mike

Mike Wahler, Jan 8, 2005
7. ### Keith ThompsonGuest

"Mike Wahler" <> writes:
> "Keith Thompson" <> wrote in message
> news:...
>> "Mike Wahler" <> writes:
>> [snip]
>> > Also please learn to indent your code.
>> >
>> > -Mike

>>
>> The OP probably did indent his code. There's a serious bug (several,
>> actually) in the new groups.google.com posting interface.

>
> This is why we always advise folks not to post code
> with tabs -- convert them to spaces first. Or is
> google mangling those too?

Google is indiscriminantly deleting leading whitespace on most lines,
both spaces and tabs. I've seen some indentation that it doesn't
delete, but I have no clue why. (I imagine this is even worse for the
Python groups.)

It also deletes multiple empty lines in some cases, and its attempt to
mask e-mail addresses mangles anything containing "@" characters
(which is a serious problem for TeX source code and the folks in
rec.games.roguelike.development).

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Keith Thompson, Jan 8, 2005
8. ### Joona I PalasteGuest

Keith Thompson <> scribbled the following:
> "Mike Wahler" <> writes:
>> "Keith Thompson" <> wrote in message
>> news:...
>>> "Mike Wahler" <> writes:
>>> [snip]
>>> > Also please learn to indent your code.
>>> >
>>> > -Mike
>>>
>>> The OP probably did indent his code. There's a serious bug (several,
>>> actually) in the new groups.google.com posting interface.

>>
>> This is why we always advise folks not to post code
>> with tabs -- convert them to spaces first. Or is
>> google mangling those too?

> Google is indiscriminantly deleting leading whitespace on most lines,
> both spaces and tabs. I've seen some indentation that it doesn't
> delete, but I have no clue why. (I imagine this is even worse for the
> Python groups.)

> It also deletes multiple empty lines in some cases, and its attempt to
> mask e-mail addresses mangles anything containing "@" characters
> (which is a serious problem for TeX source code and the folks in
> rec.games.roguelike.development).

Seems like Google is hell-bent on destroying Usenet.

--
/-- Joona Palaste () ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Outside of a dog, a book is a man's best friend. Inside a dog, it's too dark
- Groucho Marx

Joona I Palaste, Jan 9, 2005
9. ### Richards Noah \(IFR LIT MET\)Guest

"Joona I Palaste" <> wrote in message
news:crrumq\$bt0\$...
> Keith Thompson <> scribbled the following:
> > "Mike Wahler" <> writes:
> >> "Keith Thompson" <> wrote in message
> >> news:...
> >>> "Mike Wahler" <> writes:
> >>> [snip]
> >>> > Also please learn to indent your code.
> >>> >
> >>> > -Mike
> >>>
> >>> The OP probably did indent his code. There's a serious bug (several,
> >>> actually) in the new groups.google.com posting interface.
> >>
> >> This is why we always advise folks not to post code
> >> with tabs -- convert them to spaces first. Or is
> >> google mangling those too?

>
> > Google is indiscriminantly deleting leading whitespace on most lines,
> > both spaces and tabs. I've seen some indentation that it doesn't
> > delete, but I have no clue why. (I imagine this is even worse for the
> > Python groups.)

>
> > It also deletes multiple empty lines in some cases, and its attempt to
> > mask e-mail addresses mangles anything containing "@" characters
> > (which is a serious problem for TeX source code and the folks in
> > rec.games.roguelike.development).

>
> Seems like Google is hell-bent on destroying Usenet.
>
> --
> /-- Joona Palaste () ------------- Finland --------\

The easiest way to deal with Google is to prepend a "|" to every line of
code. It is annoying to have to get rid of these if you plan on
copying/pasting/compiling the code, but its easier to read with '|' and
proper indentation than without any indentation.

Richards Noah \(IFR LIT MET\), Jan 10, 2005
10. ### Keith ThompsonGuest

"Richards Noah \(IFR LIT MET\)" <> writes:
> "Joona I Palaste" <> wrote in message

[...]
>> Seems like Google is hell-bent on destroying Usenet.

>
> The easiest way to deal with Google is to prepend a "|" to every line of
> code. It is annoying to have to get rid of these if you plan on
> copying/pasting/compiling the code, but its easier to read with '|' and
> proper indentation than without any indentation.

The easist way to deal with Google is to post through
groups.google.ca, which still uses the old (working) interface.
There may be other local groups.google.* sites that will also work.

I started a separate thread on these problems, subject
"groups.google.com indentation bugs [semi-OT]". I suggest carrying on
this discussion there.

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Keith Thompson, Jan 10, 2005
11. ### Keith ThompsonGuest

Keith Thompson <> writes:
[...]
> The easist way to deal with Google is to post through
> groups.google.ca, which still uses the old (working) interface.
> There may be other local groups.google.* sites that will also work.
>
> I started a separate thread on these problems, subject
> "groups.google.com indentation bugs [semi-OT]". I suggest carrying on
> this discussion there.

But "Old Wolf" points out an apparent problem with groups.google.ca in
that thread. (It's a pity I can't redirect followups to a thread.)

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Keith Thompson, Jan 10, 2005