×

include<stdio.h>

int main() { int t,i,n; int f; scanf("%d",&t); while(t>0) { f=1; scanf("%d",&n); for(i=1;i<=n;i++) f=f*i; printf("%d\n",f); t--; } return 0; }

0★mercy779
1
accept rate: 0%

What error are you getting by this code??

(05 Jun '18, 21:16) 3★

 0 The problem with your code is that you are trying to store a number which is out of the range of int. It wouldn't have mattered even if you would have used long long because range of long long is roughly 10^19(approx 20 digits) and 100! itself has 21 zeroes at the end. So in long long you can only store upto 20! or 21!.This is why your code is wrong, assuming you have to calculate factorial of numbers greater than 20 or 21. answered 05 Jun '18, 21:36 236●5 accept rate: 17%
 0 Your code is right but you see factorials of a number is very large int can't store above factorial of 20( that too i doubt) even long long or unsigned 64-bit integer can't store value of 100!(unsigned 64-bit integer can store value upto 19 digits whereas 100! is 150+ digits)you need to be cleverer here see this has the solution http://iamit.in/blog/Spoj-Problem-Small-Factorials-FCTRL2-Explanation-and-Solution/ answered 07 Jun '18, 15:13 3★ssp547 307●7 accept rate: 25%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×255
×196
×33

question asked: 05 Jun '18, 20:49

question was seen: 132 times

last updated: 07 Jun '18, 15:13