0

I am just trying a simple maths series and i ran into something that seems quite odd to me, when i use cout << (1/4); it prints out 0, here is the code:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    long double n, d;
    n = 0;
    d = 1/4;
    int counter = 1;

    while (counter < 100)
    {
        n += 1/(counter*counter);
        counter += 1;
        cout << counter*counter << endl;
        cout << 1/(counter) << endl;
    }

    cout << d << endl;
    return 0;
}

0 Answers0