Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Recursive function: Writing the recursive case.
Write code to complete PrintFactorial()'s recursive case. Sample output if input is 5:
5! = 5 * 4 * 3 * 2 * 1 = 120
#include <stdio.h>
void PrintFactorial(int factCounter, int factValue){
int nextCounter;
int nextValue;
if (factCounter == 0) { // Base case: 0! = 1
printf("1\n");
}
else if (factCounter == 1) { // Base case: Print 1 and result
printf("%d = %d\n", factCounter, factValue);
}
else { // Recursive case
printf("%d * ", factCounter);
nextCounter = factCounter - 1;
nextValue = nextCounter * factValue;
/* Your solution goes here */
}
}
int main(void) {
int userVal;
scanf("%d", &userVal);
printf("%d! = ", userVal);
PrintFactorial(userVal, userVal);
return 0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- python3 Write a recursive function called is_palindrome(string) that takes a string parameter and checks if it is a palindrome ignoring the spaces, if any, and returns True/False. Sample output:>>> print(is_palindrome("never odd or even"))True>>> print(is_palindrome("step on no pets"))Truearrow_forwardUsing recursion, write a function sum that takes a single argument n and computes the sum of all integers between 0 and n inclusive. Do not write this function using a while or for loop. Assume n is non-negative. def sum(n): """Using recursion, computes the sum of all integers between 1 and n, inclusive. Assume n is positive. >>> sum(1) 1 >>> sum(5) # 1 + 2 + 3+ 4+ 5 15 "*** YOUR CODE HERE ***"arrow_forwardPython: How do I create a recursive function asterisk with both recursive and base cases? so for n=3, you would have below; *** ** * code that I have: for i in range(n): print("*",end="")arrow_forward
- please code in python Write a recursive function to add a positive integer b to another number a, add(a, b), where only the unit 1 can be added, For example add(5, 9) will return 14. The pseudocode is: # Base case: if b is 1, you can just return a + 1 # General case: otherwise, return the sum of 1 and what is returned by adding a and b - 1.arrow_forwardPython question Analysis: Invariants (Q16-17) For each of the following functions, identify the loop invariant, exit condition and post condition. Question 16 (Invariant 1) This function returns the list of integers that are multiples of both 3 and 7 that occurs within a given list. Identify the loop exit condition, the loop post-condition, and the loop invariant at the end of the loop, which shows the algorithm’s correctness. def multiples_count(lst): """ Input: a list of integers, lst Output: the list of integers in lst that are multiples of both 3 and 7 """ res = [] for i in range(len(lst)): if lst[i]%3 == 0 and lst[i]%7 == 0: res.append(lst[i]) # Identify the loop invariant here return res Question 17 (Invariant 2) This function checks if a given list (of comparable elements) is sorted in ascending order. Identify the loop exit condition, the loop post-condition, and the loop invariant at the end of each iteration of the loop, which…arrow_forwardNeed help Writing a function, countVowels, that accepts a string as an argument. countVowels should return the number of vowels in that string. Use recursion. example countVowels('Four score and seven years'); // => 9arrow_forward
- help in pytyhonarrow_forwardWrite a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, the pattern generated is as follows: **** *** ** * * ** *** **** Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the preceding pattern.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education