ij-macro-programming-workshop

Previous            Exercise            Next

Exercise 06.01 - Arrays - Creation and accessing elements

Aim:

Create an array containing the first five prime numbers. Replace the second and fourth element of the array by its square. Display the result.

Your code starts after this line

a = newArray(2,3,5,7,11);
a[1] = a[1] * a[1];
a[3] = a[3] * a[3];
Array.show(a);
Value
2
9
5
49
11

Your code ends before this line

The code below is for automatically checking the result. Please ignore it!

Array.getStatistics(a, min, max, mean, stdDev);
ok = min==2 && max==49 && mean==15.2 && (stdDev-19.2146)<0.000001;
if (ok) 
	showMessage("That's right. Great, you did it!");
else 
	showMessage("Your result is wrong! Please check your macro and try again!");

Previous            Exercise            Next