This project computes the factorial of a whole number entered by the client. The capacity utilizes for circle to compute the factorial and returns the number. Project ends if a non whole number is entered. This C dialect project utilizes for circle as a part of only a solitary proclamation to figures the factorial of whole number.
/*******************************************************
* MYCPLUS Sample Code - http://www.mycplus.com *
*
* This code is made accessible as a support of our *
* guests and is given entirely to the *
* motivation behind outline. *
*
* Please guide all request to saqib at mycplus.com *
*******************************************************/
#include
int fact(int n);
int main(void) {
int current;
printf("Enter a positive number [to end enter non-positive] > ");
scanf("%d", &t);
while (current > 0) {
printf("The factorial of %d is %d\n", current, fact(current));
printf("Enter a positive number [to end enter non-positive] > ");
scanf("%d", &t);
}
}
/* n is a positive number. The capacity gives back its factorial */
int fact(int n) {
int lcv;/* circle control variable */
int p;/* set to the result of the first lcv positive whole numbers */
for(p=1, lcv=2; lcv <= n; p=p*lcv, lcv++);
return p;
}