Sunday, 21 June 2015

C program to find Factorial of a given Number.

To print a factorial of a number:

Program:
#include <stdio.h>
#include <conio.h>

void main()
{
    int c, n; //Declaring Variable.
    unsigned long int fact=1;         
     
   
    printf("Enter an integer: "); //For printing
    scanf("%d",&n); //For Input.

    if ( n< 0)
        printf("Error!!! Factorial of negative number doesn't exist."); //For printing
    else
    {
       for(c=1;c<=n;++c)    //for loop 
          fact*=count;  
        
    printf("Factorial = %lu",fact); //For printing
    }

   getch(); //Getting a character or waiting for key press 
}

 
Output:



                        

No comments:

Post a Comment