Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void main()
- {
- int arg;
- Loop: scanf("%d", &arg);
- printf("%d", fat(arg));
- goto Loop;
- }
- int fat(int n) //Receives an integer as input and returns it's factorial. If the input is invalid, returns the input itself. Time complexity of O(n)
- {
- if (n == 0)
- return 1;
- int i;
- for (i = n - 1; i > 0; i--)
- n = n * i;
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement