For some reason I am not getting the desired answer and I can't fathom where the error is.
For example, given the array ar = [1,2,3]
, 1+2+3 = 6
, so return 6
, but I am getting 650462183
instead.
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <cctype>
using namespace std;
int main ()
{
int i;
cout << "enter the value of i" << endl;
cin >> i;
int arr[i];
cout << "enter the value of yout arr\n";
cin >> arr[i];
int count = 0;
for (int j = 0; j <= i; j++)
{
count += arr[j];
}
cout << count << endl;
return 0;
}