|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (9 bit)
Join Date: Nov 2002
Posts: 502
|
matrices with C
I created this program that is supposed to read two 3x3 matrices and then sum and rest the values of the first matrix against the second and store the results y another two matrices, finally it has to print the resulting matrices, when I compile the program it doesn`t find any errors but the program does not promt for the value of the firt two matrices
# include # include void main (void) { int a,b; int e[3][3]; int f[3][3]; int g[3][3]; int h[3][3]; clrscr(); printf ("\n Programa que suma y resta dos matrices"); printf ("\n Digite los datos"); for (a=1; a>=3; a++) { for (b=1; b>=3; b++) { printf ("\n e[%d][%d]= ",a,b); scanf ("%d",&e[a][b]); } } for (a=1; a>=3; a++) { for (b=1; b>=3; b++) { printf ("\n f[%d][%d]= ",a,b); scanf ("%d",&f[a][b]); } } for (a=1; a>=3; a++) { for (b=1; b>=3; b++) g[a][b]=e[a][b]+f[a][b]; } for (a=1; a>=3; a++) { for (b=1; a>=3; b++) h[a][b]=e[a][b]-f[a][b]; } printf ("\n La suma de las matrices es igual a: "); for (a=1; a>=3; a++) { for (b=1; a>=3; b++) printf ("\n g[%d][%d]",a,b); } printf ("\n La Resta de las matrices es igual a:"); for (a=1; a>=3; a++) { for (b=1; b>=3; b++) printf ("\n h[%d][%d]",a,b); } getch (); } |
|
|
|
|
|
#2 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
for (a=1; a>=3; a++)
for (b=1; b>=3; b++) All your "for loops" are wrongly written: ">=" means greater than or equal to in your case a>=3 or b>=3 will create an infinite loop! a and b will have 1 added to it infinitely! you should have used a<=3 or b<=3 or a<4 or b<4
|
|
|
|
|
|
#3 |
|
Member (9 bit)
Join Date: Nov 2002
Posts: 502
|
That was the problem, sometimes the little things has the anwers, so I am not so lost in c programming, right?
# include # include void main (void) { int a,b; int e[3][3]; int f[3][3]; int g[3][3]; int h[3][3]; clrscr(); printf ("\n Programa que suma y resta dos matrices"); printf ("\n Digite los datos"); for (a=0; a<=2; a++) { for (b=0; b<=2; b++) { printf ("\n e[%d][%d]= ",a,b); scanf ("%d",&e[a][b]); } } for (a=0; a<=2; a++) { for (b=0; b<=2; b++) { printf ("\n f[%d][%d]= ",a,b); scanf ("%d",&f[a][b]); } } for (a=0; a<=2; a++) { for (b=0; b<=2; b++) g[a][b]=e[a][b]+f[a][b]; } for (a=0; a<=2; a++) { for (b=0; b<=2; b++) h[a][b]=e[a][b]-f[a][b]; } printf ("\n La suma de las matrices es igual a: "); for (a=0; a<=2; a++) { for (b=0; b<=2; b++) printf ("\n g[%d][%d], [%d] ",a,b,g[a][b]); } printf ("\n La Resta de las matrices es igual a:"); for (a=0; a<=2; a++) { for (b=0; b<=2; b++) printf ("\n h[%d][%d], [%d]",a,b,h[a][b]); } getch (); clrscr (); } |
|
|
|
|
|
#4 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
not so lost, at all.
I can pick this sorta things up because I am in the programming business for 20 odd years, doh, I gave up my age. started programming with FORTRAN(when I was studying to be an electronic engineer), then PASCAL,C,Smalltalk...C++ so on; learning never stops, there is always something new. Last edited by alfie2; 05-07-2005 at 04:37 AM. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|