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
? Create a home page that introduces the rental car company. the page should have a header and footer. in the document body, it
Anestetic [448]
You need some more criteria. Is this a webpage? If so.. What language(s) are applicable for writing your web application. My profession is systems development, do I do a lot of fronte-end/ back-end development. I don't mind helping, just need some more information. If not what resource does this need to be created in?
7 0
3 years ago
If you sort a portion of an Excel sheet and you get an error message such as #DIV/0, what is a likely cause of the error message
yulyashka [42]
<span>If you sort a portion of an Excel sheet and you get an error message such as #DIV/0, the cause of the error message is (B) one or more cells containing absolute cell references. The possible reason of this error message includes: (1) e</span><span>ntering division formula that divided by zero (0), (2) and that is being used as a reference.</span>
7 0
3 years ago
A student has a ten-year-old desktop computer that she only uses for word processing, but she would like to start using it to pl
kondaur [170]

Answer:

1- Replace, 2- Upgrade

Explanation:

I just took the test Hopefully this helps you guys! :)

4 0
3 years ago
What are 6 external parts or perpherals of a computer system and identify output from input devices.
n200080 [17]
40. External Peripherals of a Computer systems are the following: -> Keyboard – this is an input device -> Mouse – This is an input device also -> Printer – this is an output device -> Flashdrive – This is a storage device -> Monitor – this is an output device -> external hard drive – this is a storage device Output device are those devices that communicate the results of the data processing to the user Input device are those device that communicate the results of the data processing to the computer system Storage device are those device that stores data.
4 0
3 years ago
Your sister is starting 9th grade next year and is thinking about going to college. What step would you recommend she take first
lozanna [386]

think about what she wants to do with her life and what collage is best fit for that


5 0
3 years ago
Read 2 more answers
Other questions:
  • Consider a file system that uses inodes to represent files. Disk blocks are 2KB in size and a pointer to a disk block requires 4
    13·1 answer
  • Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should
    5·1 answer
  • Building relationships during your career exploration is called
    9·2 answers
  • Both the USB flash drive and the DVD are data storage devices, but they both have numerous differences. Both can contain insane
    6·1 answer
  • Which is the most important reason you should properly cite information that you obtain from an Internet search? Question 2 opti
    8·1 answer
  • Technician A says that in any circuit, electrical current takes the path of least resistance. Technician B says that while this
    11·2 answers
  • _____ is defined as an attraction for a source based on a resemblance between the source and receiver of a message.
    15·1 answer
  • Which part of a formal email is optional
    6·2 answers
  • Drag each tile to the correct box.
    8·1 answer
  • Could anyone help me with this assignment please?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!