You should be able to figure it out yourself
I don't remember the exact logic, but I used an array of all 9 spots on the board, once player places an X somewhere set that position in the array as taken, then CPU selects randomly from the other 8 spots.
After the first 2 spots are taken and player plays his 2nd turn ( 3rd overall ), you have to check all possible combinations that would win it , For example upper left corner has X and center has X, then CPU selects lower right corner to block.
You can do this with an array and a bunch of conditions. There could be a more elegant solution out there, but by the time you find it you could have done it this way yourself. And you will also learn a few things by doing it yourself.