Search This Blog

Showing posts with label factorial. Show all posts
Showing posts with label factorial. Show all posts

Program to find FACTORIAL OF A NUMBER in Language C

WELCOME BACK CODERS, hope you are enjoying our blogs

have a good day.

Factorial says to multiply all whole numbers from the chosen number down to 1. 

The symbol is "!"

Examples: 

4! = 4 × 3 × 2 × 1 = 24
7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040


IN THIS PROGRAM THE USER NEEDS TO INPUT A NUMBER AND ITS FACTORIAL WILL BE PRINTED.


CODE


#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("Enter a number to calculate its factorial\n");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;


printf("\n Factorial=%d ",fact);
return 0;
}


OUTPUT



Download CEHv9 Study Guide PDF || Certified Ethical Hacker V9 Book

Download CEHv9 Study Guide PDF This book will be a great journey for our users in the field of cyber security . This book contains in ...