#include<stdio.h>intfacto(int);intmain(){intn,a;printf("———————————————————————————————————————————");printf("\nProgram to find the factorial of a given number");printf("\n———————————————————————————————————————————");printf("\nEnter the number ");scanf("%d",&n);if(n<0){printf("Please enter a positive number or zero");}elseif(n>15){printf("\nPlease enter a number less than 16");}else{a=facto(n);printf("\nThe factorial of %d is %d",n,a);}printf("\n———————————————————————————————————————————\n");return0;}intfacto(intn){inti,factorial=1;for(i=1;i<=n;i++){factorial=factorial*i;}return(factorial);}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 0
The factorial of 0 is 1
———————————————————————————————————————————
kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Program to find the factorial of a given number
———————————————————————————————————————————
Enter the number 25
Please enter a number less than 16
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.