Advertisement
sedran

Factorial in C

Mar 21st, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.27 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int factorial(int num) {
  4.     int a;
  5.     int result=1;
  6.     for(a=1; a<=num; a++) {
  7.         result*=a;
  8.     }
  9.     return result;
  10. }
  11.  
  12. int main(){
  13.     int i;
  14.     for(i=1; i<=6; i++) {
  15.         int k = factorial(i);
  16.         printf("%d factorial is %d\n", i, k);
  17.     }
  18.  
  19.     anykey();
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement