When a console window is finished, it closes. If you don't want it to close, ask it to do something else first. If you don't want it to close until it gets some user input, get some user input:
printf("Press the return key to close the window.\n");
getchar();
return 0;
The getchar function gets a character from the user. Usually, we'd use it as follows:
char myCharacter;
myCharacter = getchar();
But we don't want to use the character for anything - it's just a hack to get the computer to wait around. So instead of storing it in a variable, we just leave it floating around in the ether.
If your code is definitely going to be used only in Windows, you can use the getch function instead of getchar. Whereas getchar waits till the return key is pressed before returning a character, getch will return on the first keypress. You can find it in conio.h.