in turboc++
------------------------------------------------------------------------
//program to find factorial value of a number using function with returning value.
#include<stdio.h> //header file
#include<conio.h>
int factorial(); // function prototype/declaration with return type int.
int main() //main function
{
printf("value=%d",factorial());// function calling and printing output.
getch();
return 0; //returns 0 value
}
int 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
}
return facto; //returning facto value
}
----------------------------------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------------------------------------
//program to find factorial value of a number using function with returning value.
#include<stdio.h> //header file
int factorial(); // function prototype/declaration with return type int.
int main() //main function
{
printf("value=%d",factorial());// function calling and printing output.
return 0; //returns 0 value
}
int 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
}
return facto; //returning facto value
}
------------------------------------------------------------------------
//program to find factorial value of a number using function with returning value.
#include<stdio.h> //header file
#include<conio.h>
int factorial(); // function prototype/declaration with return type int.
int main() //main function
{
printf("value=%d",factorial());// function calling and printing output.
getch();
return 0; //returns 0 value
}
int 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
}
return facto; //returning facto value
}
----------------------------------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------------------------------------
//program to find factorial value of a number using function with returning value.
#include<stdio.h> //header file
int factorial(); // function prototype/declaration with return type int.
int main() //main function
{
printf("value=%d",factorial());// function calling and printing output.
return 0; //returns 0 value
}
int 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
}
return facto; //returning facto value
}
No comments:
Post a Comment