Compute factorial of any arbitratily large number/.
More...
#include <cstring>
#include <ctime>
#include <iostream>
#include "./large_number.h"
Compute factorial of any arbitratily large number/.
- Author
- Krishna Vedala
- See also
- factorial.cpp
◆ main()
int main |
( |
int | argc, |
|
|
char * | argv[] ) |
Main program
89 {
90 int number, i;
91
92 if (argc == 2) {
93 number =
atoi(argv[1]);
94 } else {
95 std::cout <<
"Enter the value of n(n starts from 0 ): ";
97 }
98
100
102 for (i = 2; i <= number; i++)
103 result *= i;
105 double time_taken =
106 static_cast<double>(end_time - start_time) / CLOCKS_PER_SEC;
107
112
116
117 return 0;
118}
Definition large_number.h:24
uint64_t result(uint64_t n)
Definition fibonacci_sum.cpp:76
bool test1()
Definition large_factorial.cpp:17
bool test2()
Definition large_factorial.cpp:54
◆ test1()
Test implementation for 10! Result must be 3628800.
- Returns
- True if test pass else False
17 {
19 unsigned int i, number = 10;
21 for (i = 2; i <= number; i++)
22 result *= i;
23
24 const char *known_reslt = "3628800";
25
26
30 return false;
31 }
32
33 const size_t N =
result.num_digits();
34 for (i = 0; i <
N; i++) {
35 if (known_reslt[i] !=
result.digit_char(i)) {
36 std::cerr << i <<
"^th digit mismatch! " << known_reslt[i]
38 return false;
39 }
40 }
41
43 return true;
44}
constexpr uint32_t N
A struct to represent sparse table for min() as their invariant function, for the given array A....
Definition sparse_table.cpp:47
◆ test2()
Test implementation for 100! The result is the 156 digit number:
9332621544394415268169923885626670049071596826438162146859296389521759
9993229915608941463976156518286253697920827223758251185210916864000000
000000000000000000
- Returns
- True if test pass else False
54 {
56 unsigned int i, number = 100;
58 for (i = 2; i <= number; i++)
59 result *= i;
60
61 const char *known_reslt =
62 "9332621544394415268169923885626670049071596826438162146859296389521759"
63 "9993229915608941463976156518286253697920827223758251185210916864000000"
64 "000000000000000000";
65
66
70 return false;
71 }
72
73 const size_t N =
result.num_digits();
74 for (i = 0; i <
N; i++) {
75 if (known_reslt[i] !=
result.digit_char(i)) {
76 std::cerr << i <<
"^th digit mismatch! " << known_reslt[i]
78 return false;
79 }
80 }
81
83 return true;
84}