Tuesday 9 April 2013

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




#include<stdio.h>
#include<conio.h>
int fact(int n)   //starting of the sub program
 {
              int f=1,i;
              if((n==0)||(n==1))  // check the condition for n value
              return(1);
              else
            for(i=1;i<=n;i++)  // perform the looping operation for calculating the factorial
              f=f*i;
  return(f);
 }
void main()
{
  int n;
  clrscr();
             printf("enter the  number :");
  scanf("%d",&n);
  printf("factoria of number%d",fact(n));
  getch();
}

No comments: