1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
denis-greek [22]
3 years ago
15

. Write a recursive function names factorial to compute the factorial of the parameter. Also write the main function, where you

ask the user to input a non-negative integer number. Then call the function factorial and display the result.
Computers and Technology
1 answer:
r-ruslan [8.4K]3 years ago
4 0

Answer:

Following are the code in c language

#include <stdio.h> // header file

long int factorial(int n); // declaration of factorial function

int main() // main function

{

   int n; // variable declaration

   printf("Enter a positive integer: ");

   scanf("%d", &n); // input number

   while(n<0) // checking the condition if number is negative

{

    printf("please enter a positive number:");

    scanf("%d", &n);

}

   printf("Factorial of %d = %ld", n, factorial(n)); // calling  factorial function

   return 0;

}

long int factorial(int n1) // recursive definition of factorial

{

   if (n1 >= 1)

       return n1*factorial(n1-1);

   else

       return 1;

}

Explanation:

In this program, it ask for a positive number input. if the value enter by user is negative then it again ask for positive input i.e positive number. Then it calls the recursive function of factorial. the recursive function factorial calculate the factorial recursively. suppose user input 4 then it goes to the if  part of program i.e return n*factorial(n-1); that means return 4*factorial(3) again recursive function call itself .this process repeated until it meets the base condition.  when a base condition meets, it return factorial of the given number.

output

Enter a positive integer: 5

factorial of 5=120

Enter a positive integer: -8

please enter a positive number:4

factorial of 4=24

You might be interested in
HELP PLEASE!!!! Which type of prototyping is most often associated with the rapid prototyping development method?
Georgia [21]

Answer:

That will be Throwaway

6 0
3 years ago
Which of the following is a Layer 3 protocol designed to permit routers to exchange information about networks that are reachabl
Nikolay [14]

Answer:

a. Routing protocol

Explanation

Routing protocol is a layer 3 (Network layer) protocol used by routers to exchange information about available routes , their associated costs and delays.

5 0
3 years ago
Read 2 more answers
What symbol following a menu command lets you know that a dialog box will be displayed? an ellipse an arrow a check mark a radio
kramer

cords   and  batteries or electric radio

5 0
2 years ago
Read 2 more answers
What is the minimum number of bits required to represent the decimal value 3001 in binary?
horsena [70]

Answer:

12 bits

Explanation:

With 12 bits you can represent numbers from 0 to 2¹²-1, i.e. 0 to 4095.

To check: with 11 bits you can only represent up to 2047, so that's not enough.

In general, to calculate the number of bits without trial and error, you can take the ²log of the number you want to represent and then round up:

²log(3001) = log(3001)/log(2) ≈ 11.55, rounded up is 12.

5 0
2 years ago
A device which is not connected to the cpu is known as?​
Dvinal [7]

Answer:

would be called an Off-line device

3 0
3 years ago
Other questions:
  • Which of the following would be a tradeoff of a scientific advancement that enables us to catch fish from the ocean faster than
    5·1 answer
  • "This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some out
    15·1 answer
  • What are the synonyms for each word? :
    5·1 answer
  • Match the careers with the education required for each job
    5·1 answer
  • . Write a swift programming code to perform following tasks a) Declare a variable that stores the age of a person b) Declare a c
    5·1 answer
  • What are the top ten alternative songs of the 2000's?
    7·1 answer
  • What is the term for an understanding about the processes that underlie memory, which emerges and improves during middle childho
    7·2 answers
  • What help in executing commands quickly
    5·1 answer
  • What is the role of computer in modern problem solving​
    13·1 answer
  • The features used be of Computer that tell, it every field.​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!