473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

printf on matrix...

Hello!

I have a matrix type of variable, lets call it matrix[2][3]...can I see on
screen it via printf?? how??

Thanks

Nov 14 '05 #1
3 8076
> I have a matrix type of variable, lets call it matrix[2][3]...can I see on
screen it via printf?? how??


for(int n=0;n<2;n++)
for(int m=0;m<3;m++)
printf("matrix[%d][%d]=%d\n",n,m,matrix[n][m]);

//jota
Nov 14 '05 #2


Bilbo wrote:
Hello!

I have a matrix type of variable, lets call it matrix[2][3]...can I see on
screen it via printf?? how??


I would put the printf in nested for loops.
Here is an example of type integer.

#include <stdio.h>

int main(void)
{
int i,j,matrix[2][3] = {{1,2,3},{4,5,6}};
for(i = 0; i < 2; i++)
{
for(j = 0;j < 3; j++)
printf("%-6d",matrix[i][j]);
putchar('\n');
}
return 0;
}

Nov 14 '05 #3
Lewis Bowers wrote:
Bilbo wrote:
I have a matrix type of variable, lets call it matrix[2][3]...
can I see on screen it via printf? How?


I would put the printf in nested for loops.
Here is an example of type integer.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {
int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};
for(size_t i = 0; i < 2; ++i) {
for(size_t j = 0; j < 3; ++j)
printf("%-6d", matrix[i][j]);
putchar('\n');
}
return EXIT_SUCCESS;
}


#include <stdlib.h>
#include <stdio.h>

int matrix_fprintf(FILE* fp, const char* format,
size_t m, size_t n, int matrix[m][n]) {
int characters = 0;
for(size_t i = 0; i < m; ++i) {
for(size_t j = 0; j < n; ++j)
characters += fprintf(fp, format, matrix[i][j]);
characters += fprintf(fp, "\n");
}
return characters;
}

int main(int argc, char* argv[]) {
int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};
matrix_fprintf(stdout, " %6d", 2, 3, matrix);
return EXIT_SUCCESS;
}
Nov 14 '05 #4

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

Similar topics

6
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...
5
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
5
by: uli | last post by:
Hi all! I'm posting to both newsgroups, because it's actually a C++ problem but could be that some of you using Matlab-&-MEX-&-C++ was struggling with the same problem. I'm trying to rewrite...
6
by: Dawn Minnis | last post by:
Hi (running Win xp and developing using Miracle C. Running applications in windows command prompt) I'm new to the group so be gentle with me. I am currently writing a C program to perform...
3
by: pranab.salian | last post by:
I need to compile some newer code in Borland TC 3.0. Here's the snippet.. /* CODE */ /* // --------------------------------------------------------------- // Shift register implementation:...
11
by: vectorizor | last post by:
Hi guys, My program deals with with lots of large matrices. To easily debug it, I would like to be able to dump them in files, so that I can easily import then in other software (think matlab,...
2
by: DarrenWeber | last post by:
Below is a module (matrix.py) with a class to implement some basic matrix operations on a 2D list. Some things puzzle me about the best way to do this (please don't refer to scipy, numpy and...
0
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
2
by: rijaalu | last post by:
I am designing a matrix class that performs addition, multicpication, substraction and division. When ever i complie the code it shows an error. include <iostream> using namespace std; class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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
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
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,...
0
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...

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.