Problem with float array

I have some problems with an array of type of float. I'm trying to program the Gauss elimination algorithm, but I get the problem that my compiler for some reason performs integer division on the elements of the array, although it's declared to be an array of type float.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <iomanip>
#include <tgmath.h>
#include <cstddef>
#include <cmath>
#include <fstream>
#include <vector>



using namespace std;


// Gauss Algorithm
int main()
{
    const size_t NDIM = 3;
    float a[NDIM][NDIM] = {-3.0, 1.0, 2.0 , 1.0, 0.0, -1.0, 4.0, -1.0, 2.0};
    float b[NDIM] = {1.0, -1.0, 8.0};
    
    
    cout << "before gauss algorithm: " << endl;
    for(int i = 0; i < NDIM; i++){
        for (int j = 0; j < NDIM; j++)
            cout << a[i][j] << " ";
        cout << b[i];
        cout << endl;}
    
    // Outer loop runs through each row
    for(int row = 0; row < NDIM; row++){
        // 1. nested loop: Divides each element in row by pivot
        for(int col = row; col < NDIM; col++)
            a[row][col]=(a[row][col])/(a[row][row]);
        b[row] /= a[row][row];
        // 2. nested loop: Subtract l*row from elements of row i
        for(int i = row + 1; i < NDIM; i++){
            double l = a[i][row] / a[row][row];
            for (int j = row; j < NDIM; j++)
                a[i][j]=a[i][j] - l*(a[row][j]);
            b[i] -= l*b[row];
        }
        cout << endl << "After elimination step: " << row + 1<< endl;
        for(int i = 0; i < NDIM; i++){
            for (int j = 0; j < NDIM; j++)
                cout << a[i][j] << " ";
            cout << b[i];
            cout << endl;}
    }
    cout << endl <<  "final shape: " << endl;
    for(int i = 0; i < NDIM; i++){
        for (int j = 0; j < NDIM; j++)
            cout << a[i][j] << " ";
        cout << b[i];
        cout << endl;}
    return 0;
}


Now the problem is with how the array stores values in it after an elimination step. It has nothing to do with the standard output.
I can't seem to find the reason why it does this right now. I'd appreciate a quick response.
Topic archived. No new replies allowed.