-1

http://www.spoj.com/problems/FCTRL2/
My code is showing compilation error in Spoj,although running accurate in my compiler.
**IDE - Codeblocks **

int cal(int );


int main()
{
  int i,t;
  int n[100];
  scanf("%d",&t);
   for(i=0;i<t;i++)
    {
       scanf("%d",&n[i]);
    }

for(i=0;i<t;i++)
{
  printf("%d",cal(n[i]));
  printf("\n");
}
return 0;
}
int cal(int x)
{
  int j,a=1;
 for(j=x;j>=1;j--)
 {
 a=a*j;


 }
 return a;


}
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Beginner
  • 721
  • 11
  • 27

2 Answers2

2

printf and scanf are not defined. You need to include the stdio library.

I get this error locally:

test.c: In function ‘main’:
test.c:8:9: warning: incompatible implicit declaration of built-in function ‘scanf’
         scanf("%d",&t);
         ^
test.c:16:16: warning: incompatible implicit declaration of built-in function ‘printf’
                printf("%d",cal(n[i]));
                ^
mirelon
  • 4,896
  • 6
  • 40
  • 70
0

For every integer input you have to calculate the factorial. This is very simple in languages like python or java which have built-in support for big integer types. Although it gives tough time for people using C / C++ or languages that do not have a built-in biginteger type.

Now, the maximum number that can be stored in an unsigned 32 bit integer is 2 ^ 32 – 1 and in an unsigned 64 bit integer is 2 ^ 64 – 1. Something like 100! has over 150 decimal digits. The data types mentioned earlier can store numbers having at most 9 and 19 decimal digits respectively. So, you need to find a way to store the 150+ digits that we will get as the answer. Think of using arrays to store each decimals.

ashwani
  • 690
  • 3
  • 16