Instructions: Each problem in this section is worth 10 points. A) Wat would be t
ID: 3552980 • Letter: I
Question
Instructions: Each problem in this section is worth 10 points.
A) Wat would be the contents of magic after Code Listing 2.1 is executed?
Code List 2.1
const int SIZE = 7;
int magic[ ] + {2, 3, 5, 7, 11, 13, 17};
int i = 1;
while(i < SIZE)
{
magic[i] = magic[i] + magic[i-1]
i++;
}
B) What would be the output of the program in Code Listing 2.2 when it is complied and executed?
Code list 2.2
#include <iostream>
using namespace std;
void mystery(int a, int &b, int &c)
{
a = b + c;
b = a + c;
c = a + b;
}
int main()
{
int a = 0, b = 1;
cout<<"a = "<<a<<" b = "<<b<<endl;
mystery(a,b,a);
cout<<"a = "<<a<<" b = "<<b<<endl;
return 0;
}
Explanation / Answer
1) {2,5,10,17,28,41,58}
2) a= 2 b = 1