You are not logged in. Please login at www.codechef.com to post your questions!

×

Why I'm getting runtime error?

#include <iostream>

using namespace std;

int factorial (int temp);

int main()
{
    int n,t;
    long long int q;
    cin>>t;
    while(t--)
    {
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>q;
    int a=factorial(n);
    int b=factorial(n-2);
    b=b*2;
    //if(n!=1)
    cout<<(a/b);
    //else cout<<1;
    }
return 0;
}
int factorial(int temp)
{
    int n=2,ans=1;
    if(temp<2)
    return 1;
    while(temp>=n)
    {
    ans=ans*n;
    cout<<"ans="<<ans<<endl;
    n++;
    }
return ans;
}

why i'm i getting runtime() error???

asked 12 Dec '13, 13:18

gauravpawar's gravatar image

2★gauravpawar
111
accept rate: 0%

edited 13 Dec '13, 15:59

kunal361's gravatar image

4★kunal361
6.0k133272


There are compilation errors in your code, remvove them first!!

link

answered 12 Dec '13, 14:33

damn_me's gravatar image

3★damn_me
2.6k21336
accept rate: 24%

The header files should be included using the #include keyword. Also clean up your code a bit. There are a lot of compilation errors too like b2 not defined. Fix these issues and you should be good to go :)

link

answered 13 Dec '13, 15:09

vigonoid's gravatar image

1★vigonoid
1682614
accept rate: 0%

Int has a range of 10^9 u can compute around 14 factorial anythng above would give you WA for sure .As for runtime error which runtime error? If its floating point error check if b doent doesnt become 0 coz of d above reason.

link

answered 14 Dec '13, 10:21

abbas's gravatar image

4★abbas
4118
accept rate: 28%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×20

question asked: 12 Dec '13, 13:18

question was seen: 634 times

last updated: 14 Dec '13, 10:21