Home > Software engineering >  Format specifies type 'double' but the argument has type 'float *' How to fix?
Format specifies type 'double' but the argument has type 'float *' How to fix?

Time:01-23

What's my mistake?

#include <stdio.h>
#include <math.h>
#include <locale.h>
#include <stdlib.h>
 int main()
{
    int j, i, F, n=4;
    float**matr; float**mass;
    printf("Начальная матрица:\n*");
    mass = (float**)malloc(n*sizeof(float));
    matr = (float**)malloc(n*sizeof(float*));
    for(i=0; i<n; i  )
    {
        matr[i]=(float*)malloc(n*sizeof(float));
        for(j=0; j<n; j  ) matr[i][j]= 9 rand() ;
    }
    for(i=0; i<n; i  ){
        for(j=0; j<n; j  ) printf("\t%2.2f",matr[i]);
        printf("\n");
    for (i=0; i<n; i  ) free (matr[i]);
    free(matr);
    free(mass);
    }
}

Problem is here:

for(j=0; j<n; j  ) printf("\t%2.2f",matr[i]);

CodePudding user response:

use printf("\t%2.2f",matr[i][j]); to print the value what you are assigned.

  •  Tags:  
  • c
  • Related