Skip to content

Instantly share code, notes, and snippets.

@lalabuy948
Created July 9, 2018 14:10
Show Gist options
  • Save lalabuy948/9cae545fdfc49ca66a08289008403bdc to your computer and use it in GitHub Desktop.
Save lalabuy948/9cae545fdfc49ca66a08289008403bdc to your computer and use it in GitHub Desktop.
Computes the factorial of number 'n' in c-lang
#include <stdio.h>
int factorial(int n){
int a = 1;
for (int i = 1; i <= n; ++i) {
a *= i;
}
return a;
}
int main() {
printf("Please enter the positive integer:");
int n;
while (scanf("%d", &n) != EOF) {
if (n > 0) {
printf("Factorial is: %d", factorial(n));
printf("\n");
} else {
printf("Please, enter positive number");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment