matrix with for loop

Mar 17, 2009 at 3:18am
hi everyone ! how do i get this goin ? i am total lost at all this c program . i am suppose to make a loop for this matrix .

#include <iostream>
#include <fstream>
using namespace std;
int main
{
ifstream is;
ofstream rez;
float matrix [3][3] ;

matrix [0][0] ;
matrix [1][2] ;

printf ("Enter an integer > ");

for (i=0; i<3; i++)
{

for (j=1; j<i; j++)
{
matrix [i][j];
printf("%d",i , "%d" ,j);
}
}

getch();

return (0);
}


*** i=0 j=0 -> i=0 j=1 -> i=0 j=2 then i will +1 ***
i=1 j=0 -> i=1 j=1 -> i=1 j=2 then i will +1
i=2 j=0 -> i=2 j=1 -> i=2 j=2 that's it .
Mar 17, 2009 at 5:12am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
 #include <fstream>
using namespace std;
int main
{
ifstream is;//?
ofstream rez;//?
float matrix [3][3] ;

matrix [0][0] ;//?
matrix [1][2] ;//?

printf ("Enter an integer > ");//?

for (i=0; i<3; i++)
{

for (j=1; j<i; j++)
{
matrix [i][j];
printf("%d",i , "%d" ,j);
}
}

getch();

return (0);
}


Something along these lines would produce your desired outcome
1
2
3
4
for(int i=0;i<3;i++)
  for(int j=0;j<3;j++)
 { array[i][j]=i,j;
  cout<<i<<","<<j<<"  ";}

the output is:
0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2
If you want it printed in 3 rows add:
if(j==2)cout<<endl;
.....before last line.
Last edited on Mar 17, 2009 at 5:37am
Mar 17, 2009 at 6:52am
is it like this ?
i am stil havin errors here and there .
no idea on what's wrong tho .

#include <iostream>
#include <fstream>

using namespace std;
int main ()
{
int i;
int j;
int array [3][3] ;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)

{ array[i][j]=i,j;
cout<<i<<","<<j<<" ";}
{ array [i][j];
printf("%d",i , "%d" ,j);}
if(j==2)cout<<endl;

return (0);
}
Mar 18, 2009 at 3:14am
First.....ignore my last post.. it is marred by obsfucation
The following is more to the point:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int array[3][3]={0};       
//write array
for(int i=0;i<3;i++)
 {
  for(int j=0;j<3;j++)
   array[i][j]=j;
   cout<<"\n";
}
//print array
for(int i=0;i<3;i++)
 { cout<<"row "<<i<<": ";
  for(int j=0;j<3;j++)
  cout<<array[i][j]<<" ";
  cout<<endl;}
system("PAUSE");
return 0;    
}

This is the output
/*
row 0: 0 1 2
row 1: 0 1 2
row 2: 0 1 2
*/
Hope this helps with attainment of your objective
Note: Use your method of pausing the DOS screen..... not system("pause")
as the experts will surely complain.
Last edited on Mar 18, 2009 at 3:18am
Topic archived. No new replies allowed.