This is the code. The compiler (Visual C++ 2010 Express) does not recognize the ifstream and ofstream even though the <fstream> header file is included. I have been writing many other codes using this type of input/output but never had this issue. Can anyone explain me why I am getting this ? Thanks in advance.
#include <fstream>
#include <cmath>
long n, m;
int suma(int j, int k);
int fact(long p);
int main(int argc, char* argv[])
{
long p;
int i;
ifstream inFILE("fact.in");
ofstream outFILE("fact.out");
inFILE >> p;
outFILE << fact(p);
return 0;
}
int suma(int j, int k)
{
long s = 0;
for (int i = 1; i <= k; i++)
{
s = s + floor(j / pow(5,(double)i));
}
return s;
}
int fact(long p)
{
int i;
long a, b, j;
if (p == 0)
return 1;
else
{
m = 1;
for(i = 1; m <= p;i++)
m = m + pow(5,(double)i);
if(p == m-1)
return -1;
else
m = m - pow(5,(double)--i);
a = ceil(p * pow(5,(double)i) / m);
b = floor((p + i) * pow(5,(double)i) / m);
for(j = a; j < b; j++)
{
if (suma(j,i) == p)
return j;
}
return -1;
}
}