C-Plus-Plus icon indicating copy to clipboard operation
C-Plus-Plus copied to clipboard

factorial calculator for large numbers. whose value could not be stored in any form of integer

Open Yashrajput7232 opened this issue 2 years ago • 6 comments

Detailed description

for example if we want to calculate the factorial of 5 we can simply calculate it as 120 and 120 can be stored in integer data type in cpp but for 100 the output cannot be stored even in long long int.

Input: 100 Output: 933262154439441526816992388562667004- 907159682643816214685929638952175999- 932299156089414639761565182862536979- 208272237582511852109168640000000000- 00000000000000

Context

when we write a program for calculating factorial by our brute force approach which is okay for small numbers but for large numbers it takes lot of time to give output on the screen and sometimes the becomes the output number is out of range of the datatypes available in programming language.

Possible implementation

Possible implementation:

1 Create an array res[] of MAX size where MAX is a number of maximum digits in output. 2 Initialize value stored in res[] as 1 and initialize res_size (size of ‘res[]’) as 1. 3 Multiply x with res[] and update res[] and res_size to store the multiplication result for all the numbers from x = 2 to n. To multiply a number x with the number stored in res[], one by one multiply x with every digit of res[]. 4 To implement multiply function perform the following steps: 4.1 Initialize carry as 0. 4.2 Do following for i = 0 to res_size – 1 4.3 Find value of res[i] * x + carry. Let this value be prod. 4.5 Update res[i] by storing the last digit of prod in it. 4.6 Update carry by storing the remaining digits in carry. 5 Put all digits of carry in res[] and increase res_size by the number of digits in carry.

Additional information

No response

Yashrajput7232 avatar Oct 07 '22 12:10 Yashrajput7232

please assign this to me

Yashrajput7232 avatar Oct 07 '22 12:10 Yashrajput7232

please assign this to me

parth9643 avatar Oct 09 '22 13:10 parth9643

Hello Sir , I would like to do this task could you assign me this task.

drashan14 avatar Oct 13 '22 12:10 drashan14

Hello, Can you please assign this issue to me? Thanks in advance :)

Sakshi2002-Sinha avatar Oct 13 '22 19:10 Sakshi2002-Sinha

Hello, Sir can you assign this task to me

yashhh-03 avatar Oct 18 '22 12:10 yashhh-03

Could you assign this task to me?

himanshukrabc avatar Oct 28 '22 14:10 himanshukrabc

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jan 17 '23 00:01 github-actions[bot]

Please ping one of the maintainers once you add more information and updates here. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

github-actions[bot] avatar Jan 25 '23 00:01 github-actions[bot]