Sunday 5 December 2010

factorial of a given number

Program that use non recursive function to find the factorial of a given integer.


Description:


Factorial of a number is nothing but the multiplication of numbers from a given number to 1 Ex: 5! =5*4*3*2*1= 120
#include<stdio.h>
#include<conio.h>
void main()
{
 long double fact=1;
 int i,n;
 clrscr();
 printf("enter any values\n");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  fact=fact*i;
 }
 printf("%d!=%Lf\n",n,fact);
 getch();
}

Output:


1.Enter the number: 7
   Factorial of number is: 5040

2. Enter the number : 6
  Factorial of number is : 720

3. Enter the number: 8
 Factorial of number is: -25216

Conclusion:


The program is error free

VIVA QUESTIONS:

1)  What is meant by call by value ?
Ans: passing values to the function as arguments
 2) What is meant by call by reference ?

Ans: passing address to the function as arguments
 3)define actual parameters ?
Ans: The actual parameters often known as arguments are specified in the function call.

No comments:

Post a Comment