c++ doubt

Hello,

Im making this code to read a specific value of the matrix. However, with this code instead of obtaining just "122" what I get is 122 repeated six time. something like:
122 122
122 122
122 122
122 122

Does anyone knows what I must change in the code in order to get just "122"?

Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include<stdio.h>
#include<stdlib.h>

float matriz [4][3] = { { 0, 21, 150 },
{ 1, 24, 200 },
{ 2, 11, 122 },
{ 3, 23, 141 } };

int main ()
{
    int i,j;
    for (i=0;i<4;i++) {
        for (j=0;j<3;j++)
            printf(" %.f",matriz[2][2]);
        printf("\n");
        }
}
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>

float matriz [4][3] = 
  { { 0, 21, 150 },
    { 1, 24, 200 },
    { 2, 11, 122 },
    { 3, 23, 141 } };

int main()
{  
  printf("%.f\n", matriz[2][2]);
}
Last edited on
Thank you so much mbozzi!!
Topic archived. No new replies allowed.