-->

program to find factorial value of a number using function.

using codeblocks
------------------------------------------------------------------------------------------------------

//program to find factorial value of a number using function.
#include<stdio.h>                      //header file
void factorial();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
factorial();                                     // function calling.
return 0;                                       //returns 0 value
}
void factorial()                             // function body line ; also called function definition
{
 int i,n,facto=1;                    // variable declaration with 1 initialization
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=1;i<=n;i++)       //loop running from 1 to n with increment 1 each time
{
       facto=facto*i;        //  multiplication of numbers repetitively
}
  
  printf("factorial value=%d\n",facto);    //display of output.
}
------------------------------------------------------------------------------------------------------------

using turboc++
-------------------------------------------------------------------------------------------------------------
//program  to find factorial value of a number using function.
#include<stdio.h>                      //header file
#include<conio.h>
void factorial();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
factorial();                                     // function calling.
getch();                                       //holds the  value
}
void factorial()                             // function body line ; also called function definition
{
 int i,n,facto=1;                    // variable declaration with 1 initialization
printf("enter a number\n");    //message display to input a number
scanf("%d",&n);                //gets input
for(i=1;i<=n;i++)       //loop running from 1 to n with increment 1 each time
{
       facto=facto*i;        //  multiplication of numbers repetitively
}
  
  printf("factorial value=%d\n",facto);    //display of output.
}


----------------------------------------
factorial value of a number 6= 6x5x4x3x2x1 or
                                                 1x2x3x4x5x6

No comments:

Post a Comment