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

×

[closed] problem in submitting answer for small factorials

/*my code for small factorial progtam*/

#include<stdio.h>
double FACT(int n) ;
int main()
{
int X,i=0;
int NUM[100];
scanf("%d",&X);
if((1<=X)&&(X<=100)){
while(i<X){
scanf("%d",&NUM[i]);
i++;
}

}
else return 0;
i=0;
while(i<X){
        if((1<=NUM[i])&&(NUM[i]<=100)){
printf("%.0lf\n",FACT(NUM[i]));
}
else return 0;
i++;
}
return 0;
}

double FACT(int n){
int i;
double sum=1;
for(i=1;i<=n;i++){
sum*=i;
}
return(sum);
}

/* i tried many times but every time it says WRONG ANSWER. What's the problem in this code now, Please help */

asked 15 Aug '13, 11:54

neel123's gravatar image

2★neel123
112
accept rate: 0%

closed 15 Aug '13, 13:38

betlista's gravatar image

3★betlista ♦♦
16.9k49115225

1

why are you asking the same question again

(15 Aug '13, 12:47) michal275★

thanks @michal27, closing...

(15 Aug '13, 13:37) betlista ♦♦3★

The question has been closed for the following reason "Duplicate Question - http://discuss.codechef.com/questions/21083/problem-in-submitting-answer-for-small-factorials" by betlista 15 Aug '13, 13:38


I used your code to calculate 100! Here is the output. Compare it with the correct answer here. Obviously, your answer is wrong. It is because of the precision issues of double. The range of values stored in a double is much higher. But, the result will be correct only in the higher order digits.

link

answered 15 Aug '13, 12:07

tijoforyou's gravatar image

2★tijoforyou
4.2k52364
accept rate: 15%

You need to use, what are known as "big integers" for this problem.

Please read the tutorial on how to solve this problem here.

(15 Aug '13, 12:09) tijoforyou2★

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: 15 Aug '13, 11:54

question was seen: 543 times

last updated: 15 Aug '13, 13:38