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

×

Only t-1 output is printing out of t test cases.Why??

#include<stdio.h>

include<stdlib.h>

int main()

{

int i,t,n,f,j;

scanf("%d\n",&t);

for(i=0;i<t;i++)

{

    scanf("%d\n",&n);

    f=1;

    for(j=1;j<=n;j++)

    {

        f=f*j;

    }

    printf("%d\n",f);


}

return 0;

}

//prog. to find factorial of small no.

asked 09 Oct '14, 02:11

itsayushbansal's gravatar image

2★itsayushbansal
116
accept rate: 0%

edited 09 Oct '14, 02:20


It is giving t correct outputs for small numbers. See this: link
BTW you are getting Wrong Ans because of maximum limit of int. Even if you use unsigned long long int, you will not be able to calculate factorial(100). This is because of overflow. i.e, size of the variable is exceeding the maximum permitted size.
Follow this link for calculating the factorial of numbers >=20 link

link

answered 09 Oct '14, 08:42

revs's gravatar image

4★revs
20013
accept rate: 20%

edited 09 Oct '14, 08:51

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:

×46
×33

question asked: 09 Oct '14, 02:11

question was seen: 447 times

last updated: 09 Oct '14, 08:51