Factorial Program In C Using Pointers With Example

Factorial Program In C Using Pointers With Example. If you are looking for a factorial program in C with pointers example, this C programming tutorial will help you to learn how to find the factorial of a number. Just go through this C programming example to calculate the factorial of a positive integer, you will be able to write an C program for factorial using pointers.

Factorial Program in C Using Pointers

Table of Contents

Factorial Program in C with Pointers

 Learn how to write a  C program for factorial using pointers. Writing a factorial program in C can be done using various techniques like using for loop, while loop, pointers, recursion function but here in this program, we show how to write a factorial program using pointers in a proper way.

Factorial Program in C using Pointers Source Code

Copy the below program to find the factorial of a number using pointers or write your own logic by using this program as a reference. Paste the factorial program into C compilers and run the program to see the result.

/* C PROGRAM FOR FACTORIAL USING POINTERS - FACTORIAL.C */

#include<stdio.h>
 
void findFactorial(int,int *); //function
int main(){
 int i,factorial,n;
 
 printf("Enter a number: ");
 scanf("%d",&n);
 
 findFactorial(n,&factorial);
 printf("Factorial of %d is: %d",n,*factorial);
 
 return 0;
}
 
void findFactorial(int n,int *factorial){
 int i;
 
 *factorial =1;
 
 for(i=1;i<=n;i++)
 *factorial=*factorial*i;
}

Factorial Program in C using Pointers Output

After you compile and run the above factorial program in c to find the factorial of a number using pointers, your C compiler asks you to enter a number to find factorial. After you enter your number, the program will be executed and give output like below expected output.

Enter a number: 7
Factorial of 7 is: 5040

C PROGRAMMING EXAMPLES

Leave a Comment