How can one write a c password program that accepts only 3 attempts of password input

You can use variable to count the number of attempt with if else condition

If you want to keep the number of attempt to be in the memory. Then you can store it the file. Like if one enter wrong password once and then closes the program, then also there will be only two attempt left as you are storing the last attempt in the memory.