Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

this "finding factorial" code does not gives expected answer when i put the number above 25. please help me!!!

+1 vote
asked Oct 18, 2018 by Saquelain Mokhtar (130 points)
#include<stdio.h>
int main()
{
    long int fact,i,j,n,t;
    scanf("%lld", &t);
    for(i=0; i<t; i++)
    {
        scanf("%lld", &n);
        fact=n;
        for(j=1; j<n; j++)
        {
            fact=fact*j;
        }
        printf("%lld\n", fact);
    }
    
}

1 Answer

0 votes
answered Oct 19, 2018 by Fady Serhan (420 points)

"because 25! is a Huge number that even can't be stored in "long int.

 .try to use "unsigned long long int" it may work since this type can store bigger numbers

you must know that computers are limited so even at long long long....int you may find that 40! is not working because that number is even bigger than the total number of AToms in earth.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...