Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int fact(int n);
- int base(int n) {
- return n;
- }
- int non_base(int n) {
- return n * fact(n-1);
- }
- int fact(int n) {
- int (*caso)(int) = (n <= 1) ? base : non_base;
- return caso(n);
- }
- int main(void) {
- int n = 0;
- printf("Inserisci un numero (intero non negativo)");
- scanf("%d", &n);
- n = fact(n);
- printf("%d", n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment