Quick question. This is the code that I wrote to finish a problem in SPOJ. The output is correct but it gives me wrong answer. Whats wrong with my code? This is the link to the question: https://www.spoj.com/problems/SUMUP/
#include <iostream>
#include <iomanip>
using namespace std;
void cal(int n){
long double a, b, c;
a = (n*n) + n;
b = 2.0 *(n*n + n + 1.0);
c = a / b;
cout<< setprecision(5) << c << '\n';
}
int main()
{ int n, z, t;
scanf("%d", &t);
const int NUMS = t;
int bobo[NUMS];
for(z = 0; z < NUMS; z++){
scanf("%d", &bobo[n]);
cal(bobo[n]);
}
return 0;
}
This is the input:
5
1
2
3
4
5
This is my output:
0.33333
0.42857
0.46154
0.47619
0.48387