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

×

Why my solution to problem is flagged wrong?

#include <stdio.h>

long factorial(int num);

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        int num;
        scanf("%d", &num);

        printf("%d\n", factorial(num));
    }

    return 0;
}

long factorial(int num)
{
    if(num == 0) return 1;
    else return (num * factorial(num - 1));
}

So this is my solution to small factorial problem, when I tested it locally it gives the desired output but when I submit this it flags it as wrong one. Can someone let me know why it is wrong? https://www.codechef.com/problems/FCTRL2

asked 17 Oct '18, 23:46

pavanjadhaw's gravatar image

0★pavanjadhaw
1
accept rate: 0%


Try something like factorial(100). You need a function to handle such big numbers. Another practice for you :)

link

answered 18 Oct '18, 00:54

tieros's gravatar image

4★tieros
734
accept rate: 12%

edited 18 Oct '18, 00:54

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:

×678
×196
×33

question asked: 17 Oct '18, 23:46

question was seen: 98 times

last updated: 18 Oct '18, 00:54