try this method,
1. freopen("NameOfInputFile.in","r",stdin); // set input file in read mode and from this file in a particular format the compiler will read all inputs and
2. freopen("NameOfOutputFile.out","w",stdout); // print output in this .out file.
Use both of them like:
int main()
{
freopen("NameOfInputFile.in","r",stdin);
freopen("NameOfOutputFile.out","w",stdout);
// start code here
.
.
.
return 0;
}