inhuman_Arif

Factorial using pointer

Oct 12th, 2021
638
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int fact(int *x, int *y)
  4. {
  5.     int i;
  6.     *y=1;
  7.     if(*x==0)
  8.         return 1;
  9.     for(i=1;i<=*x;i++)
  10.         *y = (*y)*i;
  11.     return *y;
  12. }
  13.  
  14. int main()
  15. {
  16.     int n,factorial;
  17.     scanf("%d",&n);
  18.     printf("%d\n",fact(&n,&factorial));
  19.  
  20.     return 0;
  21. }
RAW Paste Data