//Calculation
of Factorial using functions
#include <stdio.h>
#include <conio.h>
long f(int); //Declaration of function f with return type long and one parameter as integer type
void main()
{
int n;
long fact = 1; //Initialization of fact = 1
clrscr();
printf("Enter any positive integer
value\n");
scanf("%d", &n);
printf("Factorial of a number is =
%ld\n",f(n)); //%ld stands for long
getch();
}
//body of the function
//body of the function
long f(int n)
{
int i;
long res = 1;
for (i = 1; i <= n; i++)
res = res * i;
return res;
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.