What is wrong with this code Please fix code include include

What is wrong with this code? Please fix.

code:

#include <stdio.h>
#include <stdlib.h>
#define ROWS 3
#define COLS 3

void display(double[ROWS][COLS]);

double main(){

double mat[ROWS][COLS] = { {1./2, 1, 0},
{0, 2./3, 0},
{-1./2, -1, 2./3} };
display(mat);
return 0;
}

void display(double nums[ROWS][COLS]) {
double rowNum, colNum;
for (rowNum = 0.; rowNum < ROWS; rowNum++)
{
for (colNum = 0.; colNum < COLS; colNum++)
printf(\"%1.1s\", nums[rowNum][colNum]);
printf(\"\ \");
}
}

Solution

#include <stdio.h>
#include <stdlib.h>
#define ROWS 3
#define COLS 3
void display(double[ROWS][COLS]);

int main(){
double mat[ROWS][COLS] = { {1./2, 1, 0},
{0, 2./3, 0},
{-1./2, -1, 2./3} };

display(mat);
return 0;
}
void display(double nums[][COLS]) {

//problem with declaring array subscripts with double, so changed to int
int rowNum, colNum;
for (rowNum = 0.; rowNum < ROWS; rowNum++)
{
for (colNum = 0.; colNum < COLS; colNum++)
printf(\"%1.1f\\t\", nums[rowNum][colNum]);
       printf(\"\ \");
}
}

What is wrong with this code? Please fix. code: #include <stdio.h> #include <stdlib.h> #define ROWS 3 #define COLS 3 void display(double[ROWS][COLS]

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site