Monday, June 18, 2012

To find the factorial of a number using pointers


/* Program to find the factorial of a number using pointers */

#include<stdio.h>

#include<conio.h>

int findFactorial(int n, int *f);

void main()

{

  int m,fact;

  clrscr();

  printf("\n Enter a number:");

  scanf("%d",&m);

  findFactorial(m,&fact);

  printf("\n Factorial of %d is %d",m,fact);

  getch();

}

 

int findFactorial(int n,int *f)

{

  int i;

  *f=1;

  for(i=1;i<=n;i++)

   *f=*f * i;

  return (n,*f);

}

 

OUTPUT

Enter a number:5

 

 Factorial of 5 is 120

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.