-->

Program to find factorial value of a number using pointer.

using codeblocks
---------------------------------------------------------------------------
//program to get factorial value of a number using pointer
#include <stdio.h>            //header file
int main()
{
    int i,facto=1;                //variable initialization
    int number;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter a number\n");
    scanf("%d",&number);              //input of a number
    p=&number;                             //storing of address to pointer
    for(i=1;i<=*p;i++)                   //execution of loop till the value reaches to last
    {
        facto=facto*i;                   //continuous multiplication

    }
        printf("factorial value=%d",facto);       //display of output
    return 0;
}

------------------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------------------------
//program to get factorial value of a number using pointer
#include <stdio.h>            //header file
#include<conio.h>
int main()
{
    int i,facto=1;                //variable initialization
    int number;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter a number\n");
    scanf("%d",&number);              //input of a number
    p=&number;                             //storing of address to pointer
    for(i=1;i<=*p;i++)                   //execution of loop till the value reaches to last
    {
        facto=facto*i;                   //continuous multiplication

    }
        printf("factorial value=%d",facto);       //display of output
     getch();
    return 0;
}

No comments:

Post a Comment