#define SIZE 1 int main(){ SetConsoleCP(1251); SetConsoleOutputCP(1251); float arr[SIZE][SIZE]; int i,j; printf("Введите матрицу %dx %d\n",SIZE+1,SIZE+1);// ввод матрицы for(i=0;i<=SIZE;i++){ for(j=0;j<=SIZE;j++){ printf("\tArray[%d,%d]=",i,j); scanf("%f",&arr[i][j]); } printf("\n"); } system("cls"); for(i=0;i<=SIZE;i++){//вывод матрицы for(j=0;j<=SIZE;j++){ printf("Array[%d,%d] = %g \t",i,j,arr[i][j]); } printf("\n"); } return 0; } 

It is necessary to enter from the keyboard and output an array of real numbers.

But for some reason, 1 cycle is performed 3 times instead of 4. And the result is incorrect. I suspect that the problem is in the specifiers.

  • At least you have a memory jammed as you type ( i<=SIZE , j<=SIZE ), and then anything can happen. - PinkTux
  • @PinkTux, can I find out more why? Due to the use of constants? - Hardc0re
  • Because your size is SIZE , and you write down SIZE+1 data. Because indexing comes from scratch, the correct condition is not <= , but < . - PinkTux

1 answer 1

Since you defined a preprocessing constant of 1

 #define SIZE 1 

this array declaration

 float arr[SIZE][SIZE]; 

equivalent to the following ad

 float arr[1][1]; 

That is, your array has one element with indices arr[0][0] .

Therefore you should write

 printf("Введите матрицу %dx %d\n",SIZE,SIZE);// ввод матрицы ^^^^^^^^^ for(i=0;i<SIZE;i++){ ^^^^^^ for(j=0;j<SIZE;j++){ ^^^^^^ printf("\tArray[%d,%d]=",i,j); scanf("%f",&arr[i][j]); } printf("\n"); } 

Similarly, the second cycle is recorded.

Keep in mind that according to the C standard, the main function without parameters should be declared as

 int main( void )