how to turn this into c++ code.

1st part:

we have an array thats n=3

index element

x[0] = 2

x[1] = 4

x[2] = 6

Sum = 12

average = sum /n = 12/3=4

average =4

2nd part:

now this is kinda the tricky part

(x[0] - average)^2 ... => (2- 4)^2 =4

(x[1] - average)^2 ... => (4- 4)^2 =0

(x[2] - average)^2 ... => (6- 4)^2 =4

3rd part:

SumOfSquares = 4+0+4=8

result =SumOfSquares / (n-1) ..... 8 /(3-1)=4

ResultSquared= sqrt(4) =2

i know for the 1st part i need a loop to sum the values in the indeces then devide by n to get the average. the 2rd part is the most confusing for me as u have to subtract the average, square it and then u have to get the SumOfSquares for the 3rd part.

any idea how i could code this?