I need to take as an input matrix N*M from stdin & print it as a
matrix shape, something like:
|6 8 2 4 7|
|4 0 1 8 2|
|3 1 5 2 6|
|9 3 8 4 0|
I don't have any idea how exactly I do it.
Help will be appreciated! 8 2779 ro****@tauex.ta u.ac.il (Ronen Kfir) wrote in
news:b0******** *************** ***@posting.goo gle.com: I need to take as an input matrix N*M from stdin & print it as a matrix shape, something like:
|6 8 2 4 7| |4 0 1 8 2| |3 1 5 2 6| |9 3 8 4 0|
I don't have any idea how exactly I do it. Help will be appreciated!
I would start with printf().
--
- Mark ->
--
On Fri, 4 Jun 2004, Ronen Kfir wrote: I need to take as an input matrix N*M from stdin & print it as a matrix shape, something like:
First, pick one group and stick to it. Don't multi-post your
message to many different groups. If you *must* post to multiple
groups, then cross-post, like I did in this response (a response
written in response to your question in comp.lang.c, BTW).
Secondly, no matter what language you're using, you need to
know *what* you're doing before worrying about the *how*. What
kind of input is the user going to be typing? Is he going to
enter
1 2 3 4 5 6 7 8 9
and you're by magic going to print
1 2 3
4 5 6
7 8 9
or is the user going to have to tell the program how many dimensions
the matrix has, and what size it is, like this?
4 2
1 2 3 4 5 6 7 8
and then you would print a 4-by-2 matrix
1 2 3 4
5 6 7 8
Maybe the user is going to enter his matrix himself, and use some
special code to indicate that he's done entering rows, like this:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
done
In this last case, would you output
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
or would your user rather see
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
In the latter case, should the entries by justified toward the right,
the left, or centered: e.g.,
1 2 3
42 567 8
17 42 725
Should the columns all be equally wide, e.g.
1 2 65535
3 4 5
or should they have variable width, e.g.
1 2 65535
3 4 5
If the latter, then would it be acceptable to overlap
columns on particularly odd inputs, e.g.
1 2 1234567890 3 4
2 456 89 10112 7
If not, then how many spaces between columns? Are hard
tabs okay? (Hint: no. ;) Answer these questions for
yourself, and *then* think about what algorithms you'll
need to implement.
Once you know not only *what* you're doing, but also
*how* you'll do it (i.e., the algorithms involved), then
you'll finally be ready to start asking questions that
might be topical on comp.lang.c and alt.comp.lang.l earn.c-c++.
We deal with the C *language* here, not algorithms; for
algorithm help, try comp.programmin g.
-Arthur
Ronen Kfir wrote: I need to take as an input matrix N*M from stdin & print it as a matrix shape, something like:
|6 8 2 4 7| |4 0 1 8 2| |3 1 5 2 6| |9 3 8 4 0|
I don't have any idea how exactly I do it. Help will be appreciated!
Take a look at
The ANSI C Numerical Class Library: http://www.netwood.net/~edwin/svmtl/
thanx alot for all rsponses! I keep on learning...
The answer should be written in C.
The N&M are #defined. the user will be asked to enter N*M nubers &
will write one per line; number enter number enter number enter, etc.
like:
1
2
3
4
5
cheers.
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote in message news:<Pi******* *************** ************@un ix43.andrew.cmu .edu>... On Fri, 4 Jun 2004, Ronen Kfir wrote: I need to take as an input matrix N*M from stdin & print it as a matrix shape, something like:
First, pick one group and stick to it. Don't multi-post your message to many different groups. If you *must* post to multiple groups, then cross-post, like I did in this response (a response written in response to your question in comp.lang.c, BTW).
Secondly, no matter what language you're using, you need to know *what* you're doing before worrying about the *how*. What kind of input is the user going to be typing? Is he going to enter
1 2 3 4 5 6 7 8 9
and you're by magic going to print
1 2 3 4 5 6 7 8 9
or is the user going to have to tell the program how many dimensions the matrix has, and what size it is, like this?
4 2 1 2 3 4 5 6 7 8
and then you would print a 4-by-2 matrix
1 2 3 4 5 6 7 8
Maybe the user is going to enter his matrix himself, and use some special code to indicate that he's done entering rows, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 done
In this last case, would you output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
or would your user rather see
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
In the latter case, should the entries by justified toward the right, the left, or centered: e.g.,
1 2 3 42 567 8 17 42 725
Should the columns all be equally wide, e.g.
1 2 65535 3 4 5
or should they have variable width, e.g.
1 2 65535 3 4 5
If the latter, then would it be acceptable to overlap columns on particularly odd inputs, e.g.
1 2 1234567890 3 4 2 456 89 10112 7
If not, then how many spaces between columns? Are hard tabs okay? (Hint: no. ;) Answer these questions for yourself, and *then* think about what algorithms you'll need to implement.
Once you know not only *what* you're doing, but also *how* you'll do it (i.e., the algorithms involved), then you'll finally be ready to start asking questions that might be topical on comp.lang.c and alt.comp.lang.l earn.c-c++. We deal with the C *language* here, not algorithms; for algorithm help, try comp.programmin g.
-Arthur
"Ronen Kfir" <ro****@tauex.t au.ac.il> wrote: thanx alot for all rsponses! I keep on learning... The answer should be written in C. The N&M are #defined. the user will be asked to enter N*M nubers & will write one per line; number enter number enter number enter, etc. like: 1 2 3 4 5
Well, here's one obvious algorithm:
1. Define an two-dimensional array with dimensions N by M.
2. For each element in the array, read an integer value into the array.
3. For each line of the matrix:
3.1. print a | character
3.2. for each value in the line, print the value
3.3. print another | character and newline
For a toy program like this with an matrix of ints, scanf("%d", ...) should
be sufficient for the input. Remember that scanf requires the address of the
place where you want to store the input value.
Give it a go, if you have problems then post your code here.
--
Simon.
Ralmin writes: "Ronen Kfir" <ro****@tauex.t au.ac.il> wrote: thanx alot for all rsponses! I keep on learning... The answer should be written in C. The N&M are #defined. the user will be asked to enter N*M nubers & will write one per line; number enter number enter number enter, etc. like: 1 2 3 4 5
Well, here's one obvious algorithm:
1. Define an two-dimensional array with dimensions N by M.
You didn't read the problem closely enough. He said: The answer should be written in C.
C does not support two-dimensional arrays. Writing a Fortran program will
not solve his problem!
<snip>
On Sun, 6 Jun 2004, osmium wrote: Ralmin writes: "Ronen Kfir" <ro****@tauex.t au.ac.il> wrote: thanx alot for all rsponses! I keep on learning... The answer should be written in C. The N&M are #defined. the user will be asked to enter N*M nubers & will write one per line; number enter number enter number enter, etc. Well, here's one obvious algorithm:
1. Define an two-dimensional array with dimensions N by M.
You didn't read the problem closely enough. He said: The answer should be written in C.
C does not support two-dimensional arrays. Writing a Fortran program will not solve his problem!
osmium, your last two posts in this newsgroup (comp.lang.c) have
been singularly unhelpful. Do try to keep your signal-to-noise ratio
above 50%, at least.
For the OP's benefit, C supports 2-dimensional arrays using the
following syntax:
#define N 10
#define M 5
int myMatrix[N][M];
The array is then accessed in the obvious manner; e.g., 'myMatrix[i][j]'
is an object of type 'int'.
Getting back to the OP's problem, I would strongly suggest he rethink
this interface unless it's *absolutely required* by his instructor.
Can you imagine trying to enter successfully and without errors 50
integers, one per line, as per the above declarations and problem
statement? What happens if the user messes up an entry? Can he go
back and fix it, or must he run the entire program again? Remember
that on most systems, once the user hits "Enter," he's lost the ability
to edit that line of his input.
-Arthur
In article <news:Pi******* *************** ************@un ix48.andrew.cmu .edu>
Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> writes: For the OP's benefit, C supports 2-dimensional arrays using the following syntax:
#define N 10 #define M 5
int myMatrix[N][M];
The array is then accessed in the obvious manner; e.g., 'myMatrix[i][j]' is an object of type 'int'.
It is worth noting, though, that these are indeed not "true"
multidimensiona l arrays, in the sense offered by other languages
(including modern Fortran, such as F90). Instead, these are
one-dimensional arrays whose elements are in turn one-dimensional
arrays. The object "myMatrix" is a one-dimensional array of size
10. Each element myMatrix[i] is another (different) one-dimensional
array of size 5 -- hence the need for a second set of indexing
brackets, myMatrix[i][j], to select the j'th element of the i'th
array.
In languages with "real" multidimensiona l arrays, one generally
writes something like myMatrix[i,j]. Omitting either the row or
column selector is not permitted unless the operation is an "array
slice", e.g., myMatrix[,j] means "every element of myMatrix whose
second index is j". One might then write:
myMatrix[, j] +:= 3; -- this is not C code!
to add 3 to myMatrix[i,j] for all i in [0..N). Of course, C does
not offer this, and it *can*not because its arrays are really all
one-dimensional underneath.
C's "fake" multidimensiona l arrays will, of course, do the job in
this case.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ben Ingram |
last post by:
Hi all,
I am writing a template matrix class in which the template parameters are
the number of rows and number of columns. There are a number of reasons
why this is an appropriate tradeoff for my particular application. One of the
advantages is that the _compiler_ can force inner matrix dimensions used in
multiplication to agree. A _complie-time_ error will be triggered if you
write A * B and the number of coluns in A does not equal the...
|
by: SUPER_SOCKO |
last post by:
Suppose I have a matrix M x N dimension.
Normally, to print all of the elements in the matrix. I write the
following codes:
Suppose M = 5, N = 4:
for(int j=0; j<5; ++j) {
for(int k=0; k<4; ++k) {
cout << matrix << " ";
}
|
by: Fred |
last post by:
Hi.
Sorry, but I don't know where else to ask. I wrote a access shipping
database and we currently use the web interface for DHL to print shipping
labels. That means we have to manualy transpose shipto info to the DHL web
interface to print the 8 x 11 labels. We ship between 0 and 20 packages a
day.
If I get DHL pinfeed DHL shipping labels and a matrix printer, can I just
print the labels directly from my database instead of dealing...
|
by: bclegg |
last post by:
Hi,
I have a Monitoring application that needs to output single line
summaries to a local dot matrix printer loaded with line flow. ie. It
will have exclusive use of the printer which is connected to LPT1.
I need to get the normal number of lines to each page. ie 60 summaries
onto a 66 line lineflow page
Am I restricted to the Printdocument object and graphics printing or
is there a way to do a single line text print?
|
by: mahmoodbh |
last post by:
Deal All,
I have an Epson LX-300+ dot matrix printer and I would like to print one line data raw using arabic character.
As we now, the printdocument calss will not help becuase it is use the windowsXP feature and the type of paper should be specified?
Can anybody help me in that?
Regards.
| |
by: candexis |
last post by:
Hi!!!!!!!, well i want to know how to print in screen a matrix like this:
Matrix = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
And the output must be like this:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
|
by: tasukiph |
last post by:
How do I print to a dot matrix printer? I tried using pdf but when I choose to print the document there is always a margin. How do I delete the margins in pdf?
Do I have to set the invoice size? How do I dot this since the invoice is wider and shorter than a bond paper?
Should I download a special font for dot matrix printers?
Thanks!
|
by: Rillusion |
last post by:
Hi,,, just want to know how to write a a fuction to print a matrix using a call as following:
MatPrint(A,3,4);
where A is the matrix name, 3 is the number of row, 4 is the number of columns.
Thanx.........
|
by: Thekid |
last post by:
Hi, I found this sudoku solver online and it works good but I was wondering how I could get the answer that's in matrix form, to also print out in a single comma-delimited line, instead of 9 rows of 9?
from copy import deepcopy
class DeadEnd(Exception): pass
class Matrix:
def __init__(self, input):
self.rows = for i in range(9)]
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |