+ 2
Why is this code not working well
Array- for loop https://code.sololearn.com/conYo43U2PPd/?ref=app
13 Respostas
+ 8
Now it is Correct.
https://code.sololearn.com/ct8FhT979HOl/?ref=app
+ 7
What is ur expected output
+ 7
variable x is declared 2 times
+ 7
Jayakrishna🇮🇳 That's not enough...
He also has to specify array size ,otherwise the Sum doesn't give the expected output..
+ 5
Jayakrishna🇮🇳 Yes 👍
+ 3
All? Is the question solved?
+ 1
Sum of array is also missing
+ 1
The sum of all the given numbers present in array
+ 1
https://code.sololearn.com/cYba72GcejZN/?ref=app
Now it is still causing problem
Can u send me the correct code
+ 1
#include<iostream>
using namespace std;
int sum=0,x;
int main()
{
int arr[]={1,3,5,9,5,7,0,8};
//you are missing braces for loop, if you dont provide then only next 1 statement comes into a loop, so sum+=arr[x] will not part of loop.
for(int x=0;x<8;x++)
{
cout<<"print number "<<arr[x]<<endl;
sum+=arr[x];
}
cout<<"\nsum = "<<sum<<endl;
return 0;
}
Edit :
for finding array size in c/c++, you can use this formulae :
int size= sizeof(arr)/sizeof(arr[0]);
So now instead of use size as x<size;
+ 1
Alphin K Sajan anas kayani for finding array size in c/c++, you can use this formulae :
int size= sizeof(arr)/sizeof(arr[0]);
+ 1
Yes
0
Ok thanks