10323 - Factorial! You Must be Kidding!!!
Moderator: Board moderators
CE....
Some one please help me I am getting CE.....
Code: Select all
#include<stdio.h>
int main()
{
long double fact,i,n,count;
while(scanf("%Lf",&n)==1)
{
fact=1;
count=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
if(fact>6227020800)
{
count=0;
printf("Overflow!\n");
break;
}
}
if(count!=0)
{
if((fact/1000)<1)
{
printf("Underflow!\n");
}
else
{
printf("%.0Lf\n",fact);
}
}
}
return 0;
}
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Still WA...
But still........I got WA... Hear is my code........
Code: Select all
Code removed
}
Last edited by Obaida on Sun Mar 02, 2008 5:35 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Oh....no..
Code: Select all
Actually I mistake to read the problem......HA....Ha...Ha...
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Re: Oh....no..
Are you happy with that? or proud?Obaida wrote:Code: Select all
Actually I mistake to read the problem......HA....Ha...Ha...
Ok
My smile doesn't meen my happyness or my proud... It means How much I had to be careful.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Re: 10323 - Factorial! You Must be Kidding!!!
1/0 is not defined rather than infinite
the problem may have bad influence on the mathematical concept of the solver
the problem may have bad influence on the mathematical concept of the solver
Re: 10323 - Factorial! You Must be Kidding!!!
I've read all posts in this topic.
I believe that I am doing right, but unfortunately I don't. I am getting WA.
Here is my code:
Thank you..
I believe that I am doing right, but unfortunately I don't. I am getting WA.
Here is my code:
Code: Select all
#include "stdio.h"
unsigned long iter_factorial(int n) {
unsigned long accu = 1;
unsigned long i;
for(i = 1; i <= n; i++) {
accu *= i;
}
return accu;
}
int main() {
unsigned long x;
int a;
while( scanf("%d", &a) != EOF )
{
if( a <= 7 && a >= 0)
printf("Underflow!\n");
else if(a > 13)
printf("Overflow!\n");
else if(a < 0)
{
if( a / 2 * 2 == a)
printf("Underflow!\n");
else
printf("Overflow!\n");
}
else {
x = iter_factorial(a);
printf("%lu\n",x);
}
}
return 0;
}
Re: 10323 - Factorial! You Must be Kidding!!!
I didn't checked your code. But i think you should use long long.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 10323 - Factorial! You Must be Kidding!!!
My factorial function calculates the factorials of numbers between 8 and 13 [including them]. But I was getting WA.
I replaced the factorial function with the precalculated values. ( if (x == 8 ) printf("...") .....)
And I got AC.
I replaced the factorial function with the precalculated values. ( if (x == 8 ) printf("...") .....)
And I got AC.