divaughn7450 divaughn7450
  • 20-10-2020
  • Computers and Technology
contestada

Write a C program with a user defined function myFactorial, that calculates the factorial of a number entered by the user. Return the calculated factorial and print it in the main function.

Respuesta :

MrRoyal
MrRoyal MrRoyal
  • 20-10-2020

Answer:

Written in C

#include <stdio.h>

int myFactorial(int n){

   int fact = 1;

   for (int k = 1; k<=n;k++)

   {

       fact*=k;

   }

   return fact;

}

int main() {

   int num;

   printf("Number: ");

   scanf("%d",&num);

   if(num>=0)    {

       printf("%d",myFactorial(num));

   }

   return 0;

}

Explanation:

I've added the full program as an attachment where I used comments to explain some lines

Ver imagen MrRoyal
Answer Link

Otras preguntas

What is the name of N2C14? Explain how you determined the bond type and the steps you used to determine the naming convention for the compound.
In the warmer months, Ms.Selwa likes to run to school to get in her daily exercise. She can run 1/6 of a kilometer in a minute. Michael Power Saint Joseph is 3/
fill in the blanks- Heating of zinc oxide is a change.​
Please help meee WITH THIS
A tax on which of these products or services would not be considered a sin tax"? O A. Alcohol O B. Gambling O C. Electronics O D. Tobacco
HELP, please. Get it correct.
(x/a)+(x/b)=c; where a≠0, b≠0, a≠-b, solve for x
A 12-year-old boy presents to the ED after his brother bumped into his elbow while he was using a cotton-tipped swab to clean out his ear. He denies dizziness,
who is a meteorologist​
A key component to the definition of motivation involves: Group of answer choices the expectation of a desired reward or an aversive punishment. the process by