×

# 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.

116
accept rate: 0%

 0 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 answered 09 Oct '14, 08:42 4★revs 200●1●3 accept rate: 20%
 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:

×46
×33

question asked: 09 Oct '14, 02:11

question was seen: 447 times

last updated: 09 Oct '14, 08:51