Answer to Question #165891 in C++ for blessing

Question #165891

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


1
Expert's answer
2021-02-24T06:39:15-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment