Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

How to find factorial of large numbers in C

1 Answer

0 votes
#include <stdio.h>

int calculate(int pos, int arr[], int size) {
    int carry = 0;

    for (int i = 0; i < size; i++) {
        int multiply = arr[i] * pos + carry;
        arr[i] = multiply % 10;
        carry = multiply / 10;
    }

    while (carry != 0) {
        arr[size] = carry % 10;
        carry = carry / 10;
        size++;
    }

    return size;
}

void print(int arr[], int size) {
    for (int i = size - 1; i > 0; i--) {
        printf("%d", arr[i]);
    }
    printf("%d", arr[0]);
}

int main()
{
    int num = 14, arr[100] = { 0 }, size = 1;

    arr[0] = 1;

    for (int i = 2; i < num + 1; i++) { 
        size = calculate(i, arr, size); 
    } 
    
    print(arr, size);

    return 0;
}



/*
run:

87178291200

*/

 



answered Mar 2, 2023 by avibootz

Related questions

1 answer 172 views
1 answer 52 views
1 answer 99 views
1 answer 132 views
132 views asked Jan 9, 2022 by avibootz
2 answers 192 views
...