Question

5. (6 pts) What is the outputs of following section of a program? int a[10] = {1,2,3,2, 5, 6, 7, 8 , 9, y): int i - 0, 30: wh

0 0
Add a comment Improve this question Transcribed image text
Answer #1

5)

#include <iostream>

using namespace std;


int main()
{
int x=4,y=5;
int a[10]={1,2,3,x,5,6,7,8,9,y};
int i=0,s=0;
while(i<10) //possible values are 0,3,6,9
{
s=s+a[i];
i=i+3;
}
cout << s << endl; //a[0]+a[3]+a[6]+a[9]
return 0; //1 +x (4) +7 +y(5)

}

EAprogl langkff bin\Debugkfff.exe Process returned 0 〈0x0) execution time 6.238 s Press any key to continue

6)

#include <iostream>

using namespace std;


int main()
{
int x=10,y=20;
int a[10]={-1,2,x,7,-4,11,-2,-y,3,-9};
int s=0;
for(int i=0;i<10;i++)
{
if(a[i]<0)
s+=a[i]; //a[0]+a[4]+a[6]+a[7]+a[9]
// -1 + -4 +-2 + -20(y)+-9=>-36
}
cout << s << endl;
return 0;
}

EAproglc_langfffbin Debuglfff.exe 36 Process returned 0 〈0x0) Press any key to continue execution tine : 4 .122 s

7)

int *p=new int(200);

8)

#include <iostream>

using namespace std;


int main()
{
int x=10,y=20;
int a=56;
int b=38;
int u=0;
if(a>b)
u=b+x;
else
u=a+y;
cout << u << endl;
return 0;
}

48 Pro ce s s return ed 0 〈0x0〉 execution tine : 3.449 s Press any key to continue.


Add a comment
Know the answer?
Add Answer to:
5. (6 pts) What is the outputs of following section of a program? int a[10] =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT