Uva solution 10323 Factorial! You Must be Kidding!!!
#include<stdio.h>
long long int f(long long int n)
{
if(n==0)
{
return 1;
}
else
{
return n*f(n-1);
}
}
int main()
{
long long int M,N,a,b,sum;
while(scanf("%lld",&M)!=EOF)
{
sum=0;
a=f(M);
sum=a;
if(sum > 6227020800)
{
printf("Overflow! %d\n",sum);
}
if(sum < 10000)
{
printf("Underflow! %d\n",sum);
}
else
{
printf("%lld\n",sum);
}
}
return 0;
}
long long int f(long long int n)
{
if(n==0)
{
return 1;
}
else
{
return n*f(n-1);
}
}
int main()
{
long long int M,N,a,b,sum;
while(scanf("%lld",&M)!=EOF)
{
sum=0;
a=f(M);
sum=a;
if(sum > 6227020800)
{
printf("Overflow! %d\n",sum);
}
if(sum < 10000)
{
printf("Underflow! %d\n",sum);
}
else
{
printf("%lld\n",sum);
}
}
return 0;
}
Comments
Post a Comment