Skip to content

Commit

Permalink
Merge pull request #10 from shikhar96/add-shikhar
Browse files Browse the repository at this point in the history
Added factorial in C
  • Loading branch information
utkarsh-shekhar authored Oct 15, 2017
2 parents 96a5c99 + ef72a87 commit e94f5d7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions C/Factorial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
int main()
{
int n, i;
unsigned long long factorial = 1;

printf("Enter an integer: ");
scanf("%d",&n);

// show error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");

else
{
for(i=1; i<=n; ++i)
{
factorial *= i; // factorial = factorial*i;
}
printf("Factorial of %d = %llu", n, factorial);
}

return 0;
}

0 comments on commit e94f5d7

Please sign in to comment.