Wednesday, May 24, 2017

uva problem solution 10323 - Factorial! You Must be Kidding!!!


problem link

Discuss: it is just kind of tricky problem. you just can do on calculator and convert it in programming language. if it is less then and it's even or greater then 0 and less then 8  then it is underflow. if it is less then 0 and it's a odd or greater then 13 then it's overflow. otherwise you just print the factorial of n


try yourself before see the code


#include<stdio.h>
int main()
{
     long long n,f,i,j,sum;
    while(scanf("%lld",&n)!=EOF)
    {
       if((n>=0&&n<=7)||(n<0&&n%2==0))
                   printf("Underflow!\n");
                   else if((n>13)||(n<0&&n%2!=0))
                      printf("Overflow!\n");
                      else
                      {
                      sum=n;

       for(i=1;i<n;i++)
       {
           sum*=i;
       }
        printf("%lld\n",sum);
        }
    }
    return 0;
}

No comments:

Post a Comment