Write the exact output of the following algorithms:
1.1 Study the following array in an algorithm called arr. Indicate what the values in arr would be after the given code has been executed.
4
6
8
10
120
14
15
99
102
55
for x = 0 to 9
if arr(x) Mod 2 = 0 then
arr(x) = arr(x) + 5
endif
if x Mod 2 = 0 then
arr(x) = arr(x) + 1
endif
next x
x = x – 5
for y = 2 to 8 step 2
arr(y) = arr(x) + y
next y
for z = 1 to 6 step 3
arr(z) = z * y + x
next z
#include <iostream>
using namespace std;
int main()
{
int a[10] = {4, 6, 8, 10, 120, 14, 15, 99, 102, 55};
int i = 0;
int j = 2;
int k = 1;
for (; i < 10; i++)
{
if (a[i] % 2 == 0)
{
a[i] += 5;
}
if (i % 2 == 0)
{
a[i]++;
}
}
i -= 5;
for (; j < 9; j++)
{
a[j] = a[i] + j;
}
for (; k < 7; k++)
{
a[k] = k * j + i;
}
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;
return 0;
}
10 14 23 32 41 50 59 31 32 55
Comments
Leave a comment