Finding the location of the subgrid I have a $9*9$ grid and that grid consist of $ 9$  $   3*3$ subgrids , as shown in attachemnt, say that i have an index variable at 22 as marked in red , what is the formula to calculate so that i get a value 1 which is number of first subgrid because indexes are started from 0.?
 A: To find the 3x3 square in which $x$ in a 1D list representation of your grid lies, you need to compute
$$\left\lfloor\frac{\text{mod }(x,9)}{3}\right\rfloor+3\left\lfloor\frac{x}{27}\right\rfloor\text{.}$$
The square labeled $22$ is in the 1st grid, and plugging this into the formula gives
$$\left\lfloor\frac{\text{mod }(22,9)}{3}\right\rfloor+3\left\lfloor\frac{22}{27}\right\rfloor$$
$$=\left\lfloor\frac{4}{3}\right\rfloor+3\left\lfloor\frac{22}{27}\right\rfloor$$
$$=1+3(0)$$
$$=1$$
as expected.
If you are writing a program, however, I advise you to use a 2D array. This is defined in almost every language.
In C++ for example, one could define your array to be:

int grid[9][9];
grid[4][4] = 34;
std::cout << grid[4][4] << std::endl;

This program initializes a 9x9 grid, sets the value in the 5th row and column to 34, then outputs that to the screen.
To directly answer your question, in a program, the value of the 3x3 grid a certain square is in is simply

(x % 9)/3 + 3 * (x/27)

if you are using a language that doesn't automatically do flooring of division. In Python 3, for example, you would have to write

math.floor(x % 9)/3 + 3 * math.floor(x/27)

Hope this helps!
