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
Putting commands in correct order so computers can read the commands
lana66690 [7]

Answer:

its b I think I'm pretty sure

8 0
2 years ago
If you think a query is misspelled, which of the following should you do? Select all that apply.
Alik [6]

Answer:

The answer is: letter C, For obviously misspelled queries, base the utility rating on user intent.

Explanation:

The question above is related to the job of a "Search Quality Rater." There are several guidelines which the rater needs to consider in evaluating users' queries. One of these is the "User's Intent." T<u>his refers to the goal of the user. </u>A user will type something in the search engine because he is trying to look for something.

In the event that the user "obviously" misspelled queries, the rate should be based on his intent. It should never be based on why the query was misspelled or how it was spelled. So, no matter what the query looks like, you should assume that the user is, indeed, searching for something.

Rating the query will depend upon <u>how relevant or useful it is and whether it is off topic. </u>

4 0
3 years ago
Read 2 more answers
write (define) a public static method named countup, that takes one int argument and returns no value. you can safely assume tha
tester [92]

Using the knowledge of computational language in python it is possible to write a code that write (define) a public static method named countup, that takes one int argument and returns no value.

<h3>Writting the code:</h3>

<em>public class </em><em>Main</em>

<em>{</em>

<em>public static void main(</em><em>String</em><em>[] args) {</em>

<em>// testing the method </em><em>countDown </em><em>with values 5, 6, 1</em>

<em>countDown(5);</em>

<em>System.out.println();</em>

<em>countDown(6);</em>

<em>System.out.println();</em>

<em>countDown(2);</em>

<em>System.out.println();</em>

<em>}</em>

<em />

<em>public static void </em><em>countDown</em><em>(int num)</em>

<em>{</em>

<em>for (int i=1 ; i<=num ; i++) // for </em><em>loop </em><em>iterates from 1 to num</em>

<em>{</em>

<em>System.out.print(i+","); // prints num followed by comma ,</em>

<em>}</em>

<em>}</em>

<em>}</em>

See more about JAVA at brainly.com/question/12975450

#SPJ1

7 0
1 year ago
Software that interprets commands from the keyboard and mouse is also known as the what?
7nadin3 [17]
Out of the ones that you mention, the correct answer should be 
<span> Operating system</span>
3 0
3 years ago
Read 2 more answers
Copy and paste your code from the previous code practice. If you did not successfully complete it yet, please do that first befo
Gre4nikov [31]

The code practice illustrates the following concepts:

  • Arrays or Lists
  • Methods or Functions

<h3>The program in Python</h3>

The program written in Python, where comments are used to explain each action is as follows:

#This imports the random module

import random

#This defines the sumArray method

def sumArray(myList):

   #This initializes the sum to 0

   isum = 0

   #This iterates through the list

   for i in myList:

       #This adds the array elements

       isum+=i

   #This returns the sum

   return isum

#This gets the number of values    

n = int(input("Number of values: "))

#This initializes the list

myList = []

#This iterates from 0 to n - 1

for i in range(n):

   #This populates the list

   myList.append(random.randint(0,100))

#This prints the list

print(myList)

#This calls the sumArray method

print(sumArray(myList))

   

Read more about Python programs at:

brainly.com/question/24833629

#SPJ1

4 0
1 year ago
Other questions:
  • 8 POINTS!!!!!!!!
    6·2 answers
  • Using the _______ list, you can select the number of photos that will appear on each slide.
    14·1 answer
  • Write a program that responds to a positive integer passed on the command line with the number of bits needed to express that nu
    10·1 answer
  • Which of the following is NOT something you can specify in the bullets and numbering dialog box?
    8·1 answer
  • Software that function as an electronic file cabinet
    7·1 answer
  • If the predetermined overhead allocation rate is 245% of direct labor cost, and the Baking Department's direct labor cost for th
    13·1 answer
  • The main purpose of a service panel in a house is to
    11·1 answer
  • Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the ou
    10·1 answer
  • Why is John Von Neumann to a remarkable name?<br>si​
    15·1 answer
  • Which of the expressions is false? when a = 10 and b = 4
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!