what is wrong!

J

John

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.

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;
}
}
 
M

Mike Wahler

John said:
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
 
J

John

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
 
N

Nick Austin

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.
 
K

Keith Thompson

Mike Wahler said:
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.
 
M

Mike Wahler

Keith Thompson said:
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
 
K

Keith Thompson

Mike Wahler said:
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).
 
J

Joona I Palaste

Keith Thompson said:
Mike Wahler said:
Keith Thompson said:
[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 ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Outside of a dog, a book is a man's best friend. Inside a dog, it's too dark
to read anyway."
- Groucho Marx
 
R

Richards Noah \(IFR LIT MET\)

Joona I Palaste said:
Keith Thompson said:
Mike Wahler said:
[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.

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.
 
K

Keith Thompson

Richards Noah \(IFR LIT MET\) said:
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.
 
K

Keith Thompson

Keith Thompson said:
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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top