Fri May 25 2018

Factorial

C Programming876 views

File Name: factorial.c

#include<stdio.h>

int main() {

	/* Declaration of Long integer type variables */
	long int no, f = 1;
	printf("Calculate Factorial\n");
	printf("Enter a number:\n");

	/* Received Long integer type number */
	scanf("%ld", &no);
	while(no >= 1) {
		f = no * f;
		no = no - 1;
	}

	/* Print number from a Long integer type variable */
	printf("Factorial: %ld\n", f);
	return 0;
}


/* Output */
Calculate Factorial
Enter a number:
5

Factorial: 120
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.