473,508 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confusion on output

hi all,
I did the solution on the following question,but no desired output is
acheived.if you know some way on,please show me with its comments.
-----------------------------------------------------
(Declare a two-dimensional array"a" of size 10 by 10 and
read 10 integers into a[0][0] to a[0][9].Then repeat the
insertion specified by an integer sequence nine times,and
store the results from a[1] to a[9].Finally,print the array.
Output Example:
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)
-------------------------------------------------------

I did as :

#include <stdio.h>

int main()
{
int a[10][10];
int i,j,k;
int x;
for(i=0; i<10; i++){
for(j=0; j<10; j++) a[i][j]=j+1;

}

for(i=0; i<10; i++){
for(j=0; j<i+1; j++){
x= a[i][j];
a[i][j] = a[i][j];
a[i][j]=x;
for(k=0; k<10; k++)printf("%d", a[j][k]);
printf("\n");
}
printf("\n");
}
return 0;
}
but,the output is compeletly different.
tanx in advance

Nov 14 '05 #1
10 1392
Neo

"engartte" <na*****@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
hi all,
I did the solution on the following question,but no desired output is
acheived.if you know some way on,please show me with its comments.
-----------------------------------------------------
(Declare a two-dimensional array"a" of size 10 by 10 and
read 10 integers into a[0][0] to a[0][9].Then repeat the
insertion specified by an integer sequence nine times,and
store the results from a[1] to a[9].Finally,print the array.
Output Example:
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)
-------------------------------------------------------

I did as :

#include <stdio.h>

int main()
{
int a[10][10];
int i,j,k;
int x;
for(i=0; i<10; i++){
for(j=0; j<10; j++) a[i][j]=j+1;

}

for(i=0; i<10; i++){
for(j=0; j<i+1; j++){
x= a[i][j];
a[i][j] = a[i][j];
a[i][j]=x;
for(k=0; k<10; k++)printf("%d", a[j][k]);
printf("\n");
}
printf("\n");
}
return 0;
}
but,the output is compeletly different.
tanx in advance


What you actually want to store in 2-D array?
Would you make it clear, is it a predefined pattern/sequence?

-Neo
Nov 14 '05 #2
engartte wrote:
I did the solution on the following question,but no desired output is
acheived.if you know some way on,please show me with its comments.
-----------------------------------------------------
(Declare a two-dimensional array"a" of size 10 by 10 and
read 10 integers into a[0][0] to a[0][9].Then repeat the
insertion specified by an integer sequence nine times,and
store the results from a[1] to a[9].Finally,print the array.
Output Example:
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)
-------------------------------------------------------


#include <stdio.h>

void println(int a[10])
{
int i = 10;
do printf("%d", *a++); while (--i && printf(" "));
printf("\n");
}

int main()
{
int a[10][10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int i, j, k;

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

/* Feel free to add more comments to this. */
Nov 14 '05 #3
Dear Dietmar Schindler,
Thanks a lot for solution.but,If possible,please tell me more about
"println"
and the operation of this program.as for me, the use of the
term"println" is
new because I am new with C and array.

Thanks in advance

engartte

Nov 14 '05 #4
Dear Neo,

The main aim is to store the integers in 2-D array and it is same as
sorting.

thanks

Nov 14 '05 #5

"engartte" <na*****@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Dear Neo,

The main aim is to store the integers in 2-D array
He was asking if the integers stored must have particular
values, or are they arbitrary?
and it is same as
sorting.


No, storing is not at all the same as sorting. In order
to sort data, first you must store that data. Two separate
steps.

-Mike
Nov 14 '05 #6

"engartte" <na*****@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Dear Dietmar Schindler,
Thanks a lot for solution.but,If possible,please tell me more about
"println"
and the operation of this program.as for me, the use of the
term"println" is
new because I am new with C and array.


I'll reproduce his function here (but I've changed
the formatting to better accomdate my comments):

void println(int a[10])

/* Indicates that this function does not return a value,
and has one parameters which is a pointer to a type 'int'
object. */

{
int i = 10;
/* will be used as a counter (counts down rather than up) */

do
/* means to repeatedly execute the instructions between { and },
until the condition specified for 'while' evaluates to true */

{
printf("%d", *a++);

/* prints the integer at the memory address indicated by the
pointer object 'a', then increments 'a' to point to the
next integer in memory */

} while (--i && printf(" "));
/* Decrements (subtracts one from) 'i', then tests whether 'i'
is true (nonzero) or false (zero). If true, prints a blank
space and tests the return value of 'printf()' for true/false
('printf()' returns the number of characters output). Then
combines both 'true/false' results using '&&' (logical 'and'
operator), yielding a 'combined' true/false value. If true,
the loop repeats. If false, the loop terminates. */

printf("\n");
/* prints a blank line */
}

-Mike
Nov 14 '05 #7
int L1, C1;

cout<< "Matrix A" << endl;
cout<< "Lines:" << endl;
cin >>L1;
cout<< "Colums:" << endl;
cin>> C1;
int mx1 [L1][C1];
cout<<endl;
for (int m=0; m<L1; m++){
for (int n=0; n<C1; n++){
cout<< " Matrix element " << m+1 << " , " << n+1 <<endl;
cin>> mx1 [m][n];
cout<< endl;}}

for (int m=0; m<L1; m++){
for (int n=0; n<C1; n++){
cout<< mx1 [m][n]; }
cout<<endl;}
Nov 14 '05 #8
"giambi" <gi****@sapo.pt> writes:
int L1, C1;

cout<< "Matrix A" << endl;

[snip]

comp.lang.c++ is around the corner. This is comp.lang.c.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Nov 14 '05 #9
Dear Mike Wahler ,
Thanks for nice information on.It was too useful to me.
regards,
engartte

Nov 14 '05 #10
Mike Wahler wrote:
I'll reproduce his function here (but I've changed
the formatting to better accomdate my comments):
...


You did this more beautiful and accurate than I would have ever done it!

Best regards,
Dietmar
Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3144
by: Doug Farrell | last post by:
Hi all, I'm trying to do the following from within a code module: import re # text to match text = "Good morning x something /x, how are you today x something else /x"
5
2754
by: dharmesh Gupta | last post by:
i have a multifile program namely bpl.cpp-contains main() function idr.h ( class definitions) idr.cpp ( the implementation of the functions in the classes described in idr.h) bpl1.h ( contains...
3
1271
by: exits funnel | last post by:
Hello, I have the following simple program: //BEGIN CODE #include <iostream> #include <vector> class Mouse { public:
2
13884
by: googleboy | last post by:
Hi. I am trying to write out a csv file with | instead of comma, because I have a field that may have many commas in it. I read in a csv file, sort it, and want to write it out again. I read...
7
7510
by: Steve Crawford | last post by:
I am suffering some sort order confusion. Given a database, "foo", with a single character(4) column of data left padded with spaces I get: select * from foo order by somechars; somechars...
5
2839
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME thing, these are just 2 different names for the...
4
1538
by: arnuld | last post by:
I am tryign to understand the sstream class but got confused by its aspects. here is the example code: /* C++ Primer - 4/e * * Example from Section 8.5 - sstream * */
2
1290
by: VJ | last post by:
I tried to write sample code to get understanding of javascript's prototypal inheritance (along with the variety of function calling choices.. ) During the process, I got myself throughly...
2
1521
by: WalterGR | last post by:
(I've googled this to no avail.) I'm using PHP + Apache for building a website. The PHP docs for the "output_buffering" setting say: "You can enable output buffering for all files by setting...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.