Wednesday, 12 September 2012

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

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
Algorithm: main program
Step 1: start
Step 2: read n
Step 3: call the sub program fact(n)
Step 4: print the f value
Step 5: stop
            Sub program:
Step 1: initialize the f=1
Step 2: if n==0 or n=1 return 1 to main program. If not goto step 3
Step 3: perform the looping operation as follows
                        For i=1 i<=n; i++
Step 4: f=f*i
Step 5: return f value to the main program

int fact(int n)   //starting of the sub program
              int f=1,i;
              if((n==0)||(n==1))  // check the condition for n value
            for(i=1;i<=n;i++)  // perform the looping operation for calculating the factorial
void main()
  int n;
             printf("enter the  number :");
  printf("factoria of number%d",fact(n));

1.Enter the number: 7
  Factorial of number: 5040
2. Enter the number: 6
  Factorial of number: 720
3. Enter the number: 8
   Factorial of number: -25216
The program is error free


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