Pointer conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vetrivendhan
    New Member
    • Jul 2008
    • 1

    Pointer conversion

    void main()
    {
    int num,f;
    clrscr();
    printf("\nEnter a number: ");
    scanf("%d",&num );
    f=fact(num);
    printf("\nFacto rial of %d is: %d",num,f);
    getch();
    }
    int fact(int n)
    {
    if(n==1)
    return 1;
    else
    return(n*fact(n-1));
    }

    How to implmnt d above progrma in C using pointer variablesss!!!? ?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    What do you want to do with those pointer variables? btw, it's 'int main()' not 'void main()'.

    kind regards,

    Jos

    Comment

    • hdanw
      New Member
      • Feb 2008
      • 61

      #3
      Here is a pointer Variable implementation of your app:

      Code:
      int MyRecursiveFunction(int n);
      
      int (*fact)(int) = MyRecursiveFunction;
      
      void main()
      {
      int num,f;
      clrscr();
      printf("\nEnter a number: ");
      scanf("%d",&num);
      f=fact(num);
      printf("\nFactorial of %d is: %d",num,f);
      getch();
      }
      int MyRecursiveFunction(int n)
      {
      if(n==1)
      return 1;
      else
      return(n*fact(n-1));
      }

      Comment

      Working...