pages

Friday, 9 April 2021

c-program | program to calculate the factorial of the number in c-programming

 program to calculate the factorial of the number in c-programming.

In this section, we are looking for the factorial of the number by entering the value of the number by the user.
The factorial of a negative number doesn't exit and the factorial of 0 is 1.


* . In this  program takes as a positive values form the user and calculate the factorial by using "for" loop.
*. If the user entered the negative value, then the program display a custom error message.



#include<stdio.h>
#include<conio.h>
 main()
 {
     int i,n,f=1;
     printf("enter the natural number");
     scanf("%d",&n);
     for(i=n;n>=1;n=n-1)
     {
         f=f*n;
     }
     if(n>=0)
     printf("the factorial of the number is %d",f);
     else
        printf("invalid number");
     getch();
 }

output:- enter the number =5
                factorial of the number is 120


For more c-programming:-

1.c-program to check which number is plaindrome or not

2.c-program to print all prime number form 1 to n natural number.

3.







No comments:

Post a Comment