0
int main() { int b = 5; int arr[b] = {11, 35, 62, 555, 989}; int sum = 0; for (int x = 0; x < 5; x++) { sum+=arr[x]
anyone pls explain the pgm and output also print the sum
4 Antworten
+ 1
Besides the fact that you are missing a semi-colon and two closing braces, as well as the program not actually printing anything; you cannot declare an array with a non-constant variable.
Declare an array with a straight up number, like:
int arr[2] = { 1, 2 };
or declare it with a constant:
const int SIZE = 2;
int arr[SIZE] = { 1, 2 };
0
ya i missd sme lines b coz i did nt have space the other lines are
cout<<sum<<endln;
}
}
0
if i replace the x 0 to 4 the result will be 663 only bt actual output is 1652
0
sum=sum+arr[x]
for 0, 0+11=11,
for 1,11+35=46,
for 2,46+62=108,
for 3,108+555=663
for4,663+989=1652 this is ryt answer thank you guys i did not see the x<5 i calculate upto 3 values only now got the answer thank you guys