In the following simple code, I should get a zero in the output console but instead I'm getting a value 5.96046e008. Can someone please help me with this?
#include<iostream>
using namespace std;
int main()
{
int x = 1, y = 1, i, j;
float a[3][3], p;
i = x;
j = y;
p = 1.4;
a[i+1][j] = 3.5;
a[1][1] = -2.5;
a[i + 1][j] = a[x][j] * p + a[i+1][j];
cout<<a[i+1][j];
5.96046e-008 is almost zero. The size of the error is about what you'll have to expect from using float. If you want better precision you should use double (or long double).