1

I need to build a matrix. And I need to use double data type. At the same time, the data will be entered by the user. But when the data is entered; compiler program say: "ARRAY SUBSCRIPT IS AN NOT INTEGER". But I need use double data.


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    double matris[3][4];
    double i;
    double j;
    printf("Please Enter Number for Matris:\n");
    for (i = 0; i < 3; i++ ) {
        for (j = 0; j < 4; j++) {
            scanf("%lf", &matris[i][j]);
        }
    }
    for (i = 0; i < 3; i++ ) {
        for (j = 0; j < 4; j++) {
            printf("%f", &matris[i][j]);
        }
    }
    return 0;
}

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97

1 Answers1

0

The array subscript is how to index into an array. It is not the same as the type of the data in the array.

Furthermore, watch out for the format specifier and what you are printing when you output the array afterwards. Don't print the address.

int main() {
    double matris[3][4];
    int i;//<------
    int j;//<------


    printf("Please Enter Number for Matris:\n");

    for (i = 0; i < 3; i++) {
        for (j = 0; j < 4; j++) {
            scanf("%lf", &matris[i][j]);
        }
    }


    for (i = 0; i < 3; i++) {
        for (j = 0; j < 4; j++) {
            printf("%f ", matris[i][j]); //<------
        }
        printf("\n");
    }

    return 0;
}
doctorlove
  • 18,872
  • 2
  • 46
  • 62