using codeblocks
-------------------------------------------------------------------------------------------
//program to get 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 factorial_value=1,i; //initialization to value 1
int n; // variable declaration
printf("enter a number\n");
scanf("%d",&n); //input
for(i=1;i<=n;i++) //loop running from 1 to 100 with increment 1 each time
{
factorial_value=factorial_value*i; //formulation for factorial
}
printf("factorial=%d\n",factorial_value); //output
}
--------------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------------
//program to get 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 output
}
void factorial() // function body line ; also called function definition
{
int factorial_value=1,i; //initialization to value 1
int n; // variable declaration
printf("enter a number\n");
scanf("%d",&n); //input
for(i=1;i<=n;i++) //loop running from 1 to 100 with increment 1 each time
{
factorial_value=factorial_value*i; //formulation for factorial
}
printf("factorial=%d\n",factorial_value); //output
}
----------------------------------------------------------
/* here we have used top down approach. i.e calling from top and writing its body line down.
we can also reverse the process.*/
-------------------------------------------------------------------------------------------
//program to get 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 factorial_value=1,i; //initialization to value 1
int n; // variable declaration
printf("enter a number\n");
scanf("%d",&n); //input
for(i=1;i<=n;i++) //loop running from 1 to 100 with increment 1 each time
{
factorial_value=factorial_value*i; //formulation for factorial
}
printf("factorial=%d\n",factorial_value); //output
}
--------------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------------
//program to get 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 output
}
void factorial() // function body line ; also called function definition
{
int factorial_value=1,i; //initialization to value 1
int n; // variable declaration
printf("enter a number\n");
scanf("%d",&n); //input
for(i=1;i<=n;i++) //loop running from 1 to 100 with increment 1 each time
{
factorial_value=factorial_value*i; //formulation for factorial
}
printf("factorial=%d\n",factorial_value); //output
}
----------------------------------------------------------
/* here we have used top down approach. i.e calling from top and writing its body line down.
we can also reverse the process.*/
No comments:
Post a Comment