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
Explain the history of computing device of mechanical era
gayaneshka [121]

Answer:

The mechanical age can be defined as the time between 1450 and 1840. A lot of new technologies were developed in this era due to an explosion of interest in computation and information. Technologies like the slide ruler (an analog computer used for multiplying and dividing) were invented in this period.

5 0
3 years ago
Question # 9
Ganezh [65]

Answer:

flight stimulators are used to train astronaut and design simple air craft

8 0
2 years ago
1. It manages the computer's memory and processes, as well as all of its software and hardware.
8_murik_8 [283]

Answer:

B. Computer operating system

Explanation:

the operating system (or OS) manages all of the hardware and software in the computer, and allows hardware and software to communicate.

We can also figure this out by process of elimination: Application software is just a fancy way to say apps, Graphical User Interface (or GUI) are menus that allow a user to use the computer through a visual representation (what you interact with using your mouse), and microcomputer just means a small computer like a laptop or a phone.

6 0
3 years ago
To build a framework for security policies and controls, one can use the following approach: 1) document the concepts and princi
serious [3.7K]

Answer:

n/a

Explanation:

4 0
3 years ago
Which type of database program is Microsoft Access 2016?
nadya68 [22]

Answer:

O relational

Explanation:

If I'm wrong I'm so so sorry! But form my research it keeps saying its relational.

If I'm right please give me brainliest I really need it to level up so please help me!

If you don't know how to give brainliest there should be a crown underneath my answer you just have to click it.

Thank you and have a wonderful night,morning,afternoon/day! :D

6 0
3 years ago
Read 2 more answers
Other questions:
  • What skills and characteristics do you think would be necessary for a lighting board operator to be successful?
    8·2 answers
  • The 2 main types of copyright relevant to the recording industry?
    5·2 answers
  • As long as users refer to files in the ____ directory, they can access the files without entering the absolute filename.
    10·1 answer
  • Monica wants insert a cover page for her report. She needs to be sure her insertion point is at the beginning of the report.
    7·1 answer
  • What shoul i get, Airpods or a ps4 cooling fan ???
    7·2 answers
  • The model for Diminishing Marginal Utility is ______ in nature.
    12·1 answer
  • Lists and Procedures Pseudocode Practice For each situation, provide a pseudocoded algorithm that would accomplish the task. Mak
    8·1 answer
  • Which type of word processing programs enables users to include illustrations within the program?
    10·2 answers
  • Hurry please I’ll give Brainliest if you are right
    5·1 answer
  • Which statement best describes one reason why assembly language is easier
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!