C Programming

Factorial

Learn C programming for generate factorial of a user given number

5/25/2018
0 views
factorial.cC
#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
C languageC programmingc codingfactorial number

Related Examples

Mashable is a global, multi-platform media and entertainment company For more queries and news contact us on this
Email: info@mashablepartners.com