I created a function seriesSum
to return a sum of the series of a number, and I used long long
return data type but it returns a negative number if I insert for example 46341
output will be -1073716337
and what I am expected is 1073767311
here is my code:
#include <iostream>
using namespace std;
long long seriesSum(int n)
{return n*(n+1)/2;}
int main()
{
cout<<seriesSum(46341); // expected 1073767311 but output is -1073716337
return 0;
}