QUOTE(pac213 @ 3 Sep, 2007 - 09:59 AM)

CODE
#include <cmath>
#include <malloc.h>
#include <iostream.h>
#include <process.h>
#include <stdio.h>
using namespace std;
void main()
{
unsigned int d; //number of digits
unsigned char *a;
unsigned int j, n, q, z, t;
int i;
double p;
cout << "\nEnter the No\t:";
cin >> n;
p = 0.0; //calculate the number of digits required
for(j = 2; j <= n; j++)
p += log10(j);
d = (int)p + 1;
a = (unsigned char*)malloc(d*sizeof(unsigned char));
if (!a)
{
cout << "Could not allocate memory!!!";
exit(0);
}
for (i = 1; i < d; i++)
a[i] = 0; //initialize
a[0] = 1;
p = 0.0;
for (j = 2; j <= n; j++)
{
q = 0; //initialize remainder to be 0
p += log10(j);
z = (int)p + 1;
for (i = 0; i <= z/*NUMDIGITS*/; i++)
{
t = (a[i] * j) + q;
q = (t / 10);
a[i] = (char)(t % 10);
}
}
cout << "\nThe Factorial is\n";
// the fact is stored ulta..
for( i = d -1; i >= 0; i--)
{
cout << (int)a[i];
}
}
whenever i run this i always get this errors
1>c:\documents and settings\god\my documents\visual studio 2005\projects\fack\fack\fack.cpp(21) : error C2668: 'log10' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 8\vc\include\math.h(569): could be 'long double log10(long double)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(521): or 'float log10(float)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(122): or 'double log10(double)'
1> while trying to match the argument list '(unsigned int)'
1>c:\documents and settings\god\my documents\visual studio 2005\projects\fack\fack\fack.cpp(31) : warning C4018: '<' : signed/unsigned mismatch
1>c:\documents and settings\god\my documents\visual studio 2005\projects\fack\fack\fack.cpp(40) : error C2668: 'log10' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 8\vc\include\math.h(569): could be 'long double log10(long double)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(521): or 'float log10(float)'
1> c:\program files\microsoft visual studio 8\vc\include\math.h(122): or 'double log10(double)'
1> while trying to match the argument list '(unsigned int)'
1>c:\documents and settings\god\my documents\visual studio 2005\projects\fack\fack\fack.cpp(42) : warning C4018: '<=' : signed/unsigned mismatch
ive tried some tips, but it didnt help me...
main function needs to return 0.
#include <iostream>
#include<cmath>
using namespace std;
unsigned int d; //number of digits
unsigned char *a;
unsigned int j, n, q, z, t;
int i;
double p;
cout << "\n\tEnter the No: ";
cin >> n;
p = 0.0; //calculate the number of digits required
for(j = 2; j <= n; j++)
p += log10(j);
d = (int)p + 1;
a = (unsigned char*)malloc(d*sizeof(unsigned char));
if (!a) {
cout << "\tCould not allocate memory!!!";
exit(0);
}
for (i = 1; i < d; i++)
a[i] = 0; //initialize
a[0] = 1;
p = 0.0;
for (j = 2; j <= n; j++) {
q = 0; //initialize remainder to be 0
p += log10(j);;
z = (int)p + 1;
for (i = 0; i <= z/*NUMDIGITS*/; i++) {
t = (a[i] * j) + q;
q = (t / 10);
a[i] = (char)(t % 10);
}
}
cout << "\tThe Factorial is ";
// the fact is stored ulta..
for( i = d -1; i >= 0; i--) {
cout << (int)a[i];
}
cout << ".\n";
return 0;
}
Hope that helps! I am on a mac and the above program works in Xcode.
barnwillyb