Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computer Engineering: Language \"C Programming\" 1. Factorial (fact.c) The facto

ID: 3145128 • Letter: C

Question

Computer Engineering:

Language "C Programming"

1. Factorial (fact.c) The factorial of a positive integer is defined as n! nn -1n 2.1 and by definition 0! Write a program that prompts the user to enter an integer number and uses a function, factorial, described below, to calculate the factorial of that number. Implement this function: long factorial(int n) Sample Output: Number to calculate for: 5 5!120 Data Type Requirement: Input data for the factorial function is of type int, output is of type long. Input Validation: Input value must be greater than equal to 0

Explanation / Answer

#include <stdio.h>
int main()
{
int i,n;

printf("enter the number ");

scanf("%d",&n);

if(n<0)

{

printf("we cannot find factorial for the entered input ");

}

else

{

factorial(n);

}return 0;

}

long factorial(int n)

{

int i; long f = 1;

for(i=1;i<=n;i++)

f=f*i;

return(f)

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote