runtime error..help me out plzz!!

#include<stdio.h>
void main()
{
int tc,num,i;
scanf("%d",&tc);
for(i=tc;i>0;i–)
{
scanf("%d",&num);
printf("%d\n",fact(num));
}
}
int fact(int n)
{
int c,f=1;
for(c=1;c<=n;c++)
{
f=f*c;
}
return f;
}

You need to declare the function prototypes whenever you are defining the function after main function.
The following code is working on visual studio…

// ConsoleApplication2.c : Defines the entry point for the console application.
//


#include <stdio.h>
int fact(int n);
void main()
 { 
  int tc,num,i; 
  scanf_s("%d",&tc);
  for(i=tc;i>0;i--)
   {   
          scanf_s("%d",&num); 
	   printf("%d\n",fact(num));
   } 
}
	    
 int fact(int n) 
{ 
int c,f=1;
    for(c=1;c<=n;c++)
       {
        f=f*c;
       }
         return f; 
         
    }

Hello,

I wouldn’t advise you to use Visual Studio as programs here are compiled with the GNU Compiler Collection often known as gcc, so, using Visual Studio can lead to weird behaviours on the online judge.

Regarding your code, the most obvious error is declaring main() as a void function.

In C/C++ programs, main() should ALWAYS return 0; and be declared as int main().

Also, after fixing it you will get a Wrong Answer veredict…

Note that the limit of the factorial is 100.

A number like 100! is over 600 decimal digits which is way beyond the capacity of any built-in data type and, either a language that supports big integers, or big integers arithmetics should be used in order to get Accepted.

If you’d like to, you can read a tutorial I wrote about it, here.

Best of luck,

Bruno

1 Like

thanx for help…m again tryin from scratch!!

//