Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what is wrong!

Reply
Thread Tools

what is wrong!

 
 
John
Guest
Posts: n/a
 
      01-08-2005
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][i]);


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

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

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

}


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

--
John

 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      01-08-2005

"John" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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



 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      01-08-2005
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

 
Reply With Quote
 
Nick Austin
Guest
Posts: n/a
 
      01-08-2005
On 8 Jan 2005 07:20:31 -0800, "John" <(E-Mail Removed)> 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[i][j]);
>}
> printf("\n");
> return 0;
> }


Nick.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-08-2005
"Mike Wahler" <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-08-2005

"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Mike Wahler" <(E-Mail Removed)> 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


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-08-2005
"Mike Wahler" <(E-Mail Removed)> writes:
> "Keith Thompson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> "Mike Wahler" <(E-Mail Removed)> 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) (E-Mail Removed) <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.
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      01-09-2005
Keith Thompson <(E-Mail Removed)> scribbled the following:
> "Mike Wahler" <(E-Mail Removed)> writes:
>> "Keith Thompson" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> "Mike Wahler" <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- 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
 
Reply With Quote
 
Richards Noah \(IFR LIT MET\)
Guest
Posts: n/a
 
      01-10-2005
"Joona I Palaste" <(E-Mail Removed)> wrote in message
news:crrumq$bt0$(E-Mail Removed)...
> Keith Thompson <(E-Mail Removed)> scribbled the following:
> > "Mike Wahler" <(E-Mail Removed)> writes:
> >> "Keith Thompson" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >>> "Mike Wahler" <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- 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.


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-10-2005
"Richards Noah \(IFR LIT MET\)" <(E-Mail Removed)> writes:
> "Joona I Palaste" <(E-Mail Removed)> 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) (E-Mail Removed) <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments