File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -211,4 +211,35 @@ int main() {
211
211
}
212
212
```
213
213
214
+ ## Υπολογισμός παραγοντικού / factorial - χρήση αναδρομής - lec11
215
+
216
+ Credits: Στέφανος
217
+
218
+ ``` c
219
+ /* Short program for computing the factorial
220
+ of a number. Does not handle edge-cases
221
+ like negative numbers. */
222
+ #include < stdio.h>
223
+ #include < stdlib.h>
224
+
225
+ int factorial (int num) {
226
+ printf("Computing: factorial(%d)\n", num);
227
+ if (num <= 1) {
228
+ return 1;
229
+ } else {
230
+ return num * factorial(num - 1);
231
+ }
232
+ }
233
+
234
+ int main(int argc, char ** argv) {
235
+ if (argc != 2) {
236
+ printf("Run this program as ./factorial <num >\n");
237
+ return 1;
238
+ }
239
+ int num = atoi(argv[ 1] );
240
+ printf("The factorial of this number is: %d\n", factorial(num));
241
+ return 0;
242
+ }
243
+ ```
244
+
214
245
You can’t perform that action at this time.
0 commit comments