Find elements

Factorial program using the pointer in C++ language

Factorial program  using the pointer in C++ language

In this tutorial, we will discuss the concept of Factorial program  using the pointer in C++ language

In this post, we will learn how to calculate factorial of a number using the pointer in C++ language and go through the given C++ example to calculate the factorial of a positive integer

Factorial is a product of all positive descending integer begins with a specified number (n) and calculates up to one

Example

factorial of 5 is

5!=5*4*3*2*1=120

 

factorial of 4 is

4!=4*3*2*1=24

 

factorial of n is

n!=n*(n-1)*....2*1
Factorial of a given number

Program 1

The program allows the user to enter a number (a positive integer) and then it calculates factorial of given number using pointer variable in C ++ programming language

 

//Factorial program using the pointer in C++ language
#include <iostream>
#include <conio.h>
using namespace std;

void findFactorial(int, int *);//Function prototype
int main()
{
    int i,fact,num;//variable declaration
    cout<<"Enter a number: \n";
    cin>>num;//Takes input from the user
    findFactorial(num, &fact);//function call
    cout<<"Factorial of " <<num<< " is: "<<fact;
    //display the factorial of given number
    getch();
    return 0;
}

//function definition with parameter
void findFactorial(int num, int *fact){
int i;

*fact=1;

for(i=1; i<=num; i++){//calculate factorial using for loop
*fact=*fact*i;
}
}

When the above code is executed, it produces the following results

Enter a number
5
Factorial of 5 is: 120

 

 

Suggested for you

Data type in C++ language

Variable in C++ language

The operator in C++ language

Pointer in C++ language

 

Similar post

Find factorial  of a number in C++ language

Find factorial of a number using the function in C++ language

Find factorial of a number using the function in C language

Find factorial  of a number in C language

Factorial program in C language using the pointer

Find factorial of a number  using the recursion in Java language

Find factorial of a number  using the recursion in C language

Find factorial of a number  in Java

Find factorial of a number  in Python language

Find factorial of a number  in Java using method

Find factorial of a number  in Python using the function

Find factorial of a number  using the pointer in C language

Find factorial of a number  using the pointer in C++ language

 

 

 

 

Factorial calculation of a number using the pointer in C
Java program to reverse a number using loops
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 week ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

3 weeks ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

4 weeks ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

4 weeks ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

1 month ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

1 month ago