Simple input question first test case is giving right ans others are nshowing error

my code is #include
using namespace std;
int main(){
int i;
long long int arr[1000000];
int n=sizeof(arr);
int sum=0;
for(i=0;i<n;i++){
cin>>arr[i];}
for(int i=0;i<n;i++){
sum=sum+arr[i];
if(sum>=0)
cout<<arr[i];
else {
break;
}}

}

HI @Anoushka_1805, you have not used the sizeof operator correctly. Correct way will be:

int n = sizeof(arr) / sizeof(arr[0])
And here what your code is doing is, input an array. Then add every value in that array one by one in sum variable and after that print its ith element.
Is that what you want to do ?!?!?!

1 Like

yes this is what quest is asking
if i give any inputs it is giving right ans

So everything cool ?! Your doubt is resolved ? If yes then please mark it as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.