What does this function do? def f2(s): i=len(s)-1 while(i>=0): print(s[i],end="") i=i-1 A It prints the reverse of its parameter s B It counts the number of 'a' characters in its parameter s C It counts the number of 's' characters in its parameter s D It prints its parameter s Question 6 What's wrong with this code? i=10 while(i>100): print('Ali') i=i+1 It produces nothing
Q: A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are…
A: A palindrome reads the same, when read straight or in reverse. A palindrome may be a single word or…
Q: Implement the following: 1) Define a function subMessage() which takes two parameters, a and b. a is…
A: Program import random def subMessage(text1,n): substr=text1[0:n] print(substr) n =…
Q: Write a recursive function called that takes a string of single names separated by spaces and prints…
A: Required: Write a recursive function called that takes a string of single names separated by…
Q: Write an iterative version of the function defined in Self-Test Exercise 2. (Write a recursive void…
A: A recursive function is a function which calls itself until some condition is true. The iterative…
Q: Write a recursive function named reverseWithinBounds that has an argument that is an array of…
A: Q: Code the given problem
Q: LTtZ|J/ 2/ turtle.right(180) tee2(S/2) turtle.left(90) turtle.back(S) def tee2(S): turtle.forward(S)…
A: The program defines a single function tee( ), which accepts two parameter: S: The height of the…
Q: Consider the following function: void fun_with_recursion(int x) { printf("%i\n", x);…
A: According to the question below the solution
Q: Cyclops numbers def is_cyclops(n): A nonnegative integer is said to be a cyclops number if it…
A: Given: Cyclops numbersdef is_cyclops(n):A nonnegative integer is said to be a cyclops number if it…
Q: function myCompose(f,g){// TODO: return (f o g);// that is, a function that returns f(g(x))…
A:
Q: es a substring with a new string. Example: >>> replace('The quick brown fox jumps over the lazy…
A: Given : Write a function that replaces a substring with a new string. Example:>>>…
Q: Please answer it in Python Write a function show_winner that takes as an argument a dictionary of…
A: def Show_winner(dictonary): #First find smallest score smallest = 99999 for i in…
Q: python this is connected to the last problem - the second part of the question is added. my attempt…
A: Task : Using the given set of values of n from 2 to 1000 : show that harmonic_sim(n) approaches…
Q: Write a c++ program that takes a date in the following format: December 24th, 2021 and extracts the…
A: The code for c++
Q: Pointers, modified) by Catherine Arellano We have a new game show that pits three people against…
A:
Q: Design a class ProblemSolution to overload a function solution. Write a function int…
A: import java.util.*; public class ProblemSolution{ static int solution(int N, char CH) { //…
Q: d. Write a function Encode as follows: • // Return M^e mod PQ • int Encode (int M, int e, int PQ);…
A: RSA is a public key encryption algorithm used for secure data transmission. The key generation in…
Q: Function power of type real - int - real that raises a real number to an integer power. For example…
A: Function power of type real * int - real......
Q: Write a function decimal_to_binary(decimal_number) that takes in a non-negative integer and returns…
A: logic :- If number>1 call again with n//2 parameter. print(n%2)
Q: solve the problem in java: Consider the are n=2 subjects and needed =[4,5] answered questions, to…
A: imports used import java.util.*;
Q: Look at the differences between max1 and max2 2. What is the difference? 3. Do the two functions do…
A: Dear Student, In C language 2D arrays are stored in the memory continuously in the row major order…
Q: vi) Write a function in Javascript that takes an integer n as the parameter and returns the number n…
A: I have answered this question in step 2.
Q: Write a function that counts and returns the number of vowels in a word. The function's one…
A: Given data is shown below: Write a function that counts and returns the number of vowels in a word.…
Q: mplement a recursive C++ function which takes an array of integers (arr) and the starting (start)…
A: Step 1:- Program Approach:- 1.Declare the user-define function whose name is int findLargest(int…
Q: Q6 In Python implement a recursive function named test() that accepts an integer parameter. If the…
A: Student :- 1. I will provide the code 2. I will provide the output
Q: Fibonacci numbers are a sequence of integers, starting with 1, where the value of each number is the…
A: Program plan: With RECURSION Prompt for a number Pass this number to function Fibonacci. Check if…
Q: Write a c++ program that takes a date in the following format: December 24th, 2021 and extracts the…
A: The program is written in c++. Here, December 24th, 2021 and extracts the day, month, and year as 3…
Q: #Quiz #Make a class that has 2 pieces of data (x, y) #In the init, take x as a parameter and ask the…
A: Purpose of the program: This program would create a class including the following functionalities…
Q: What will the following C function print? Be exact! void foo (int a) { int * p1 = &a; int **p2 spl;…
A: int* is the pointer variable which stores the address of an integer variable and int** is the…
Q: Please answer it in Python 1) Write a function last_consonant that takes as an argument a word and…
A: as per our policy i have given only one answer question 1.
Q: Write a function count_evens() that has four integer parameters, and returns the count of parameters…
A: logic:- within function use if statement to check remainder when divided by 2 is 0 or not. count=0…
Q: . Find Relatively Prime Write a function to return a number that is relatively prime with the given…
A: Actually, function is a group of statements. The given information is: * return an integer that is…
Q: wing program void test () { int i; int [5] a; void f(int x) { a[i] = 5; i = i + 1; i = x; i = 1;…
A: Given values I=1 a[1] = 7 Function f(a[I]) Means a[1] is passed to function which is 7 Now {…
Q: a python function called replacer() that takes two strings as arguments. Argument1: A…
A: here have to determine about python code for replace string.
Q: ou'll implement a function powerLoop(upto: int) -> None that takes an integer param :0 and returns…
A: I have given python code with proper input and output below..
Q: Write a recursive function called that takes a string of single names separated by spaces and prints…
A: The python program generates the combination or permutation of a word from the user input sentence.…
Q: Write a function check_vowels() that gets a string as a parameter and check if every vowel is…
A: Required:
Q: def all_fluffy(s: str) -> bool: "*"Return True iff every letter in s is fluffy. Fluffy letters are…
A: According to the Question below the solution: Output:
Q: Write a function nesting(), which takes an arbitrary number of parameters, and returns a list…
A: Write a function nesting(), which takes an arbitrary number of parameters, and returns a list…
Q: Write a function "sumofEven" that takes an int "n" and returns the sum of all even integers starting…
A: We have to write a function "sumOfEven" to find sum of even numbers from 1 to n we have given sample…
Q: 1- import java.util.Scanner; 2 3 public class Countdown 4- [ 5 6- 7 8 9 10 11 12 13 14 15 16 17 18…
A: Below I have provided JAVA Programming. Also, I have attached the screenshot of the code and output…
Q: The following function f uses recursion: def f(n): if n 0 a <- a + i + (i-1) return a c) def f(n):…
A: The given recursive function calculates nth fibonacci number. Option a would have been correct if…
Q: a) Implement a function start( ) that takes as input a positive number a, rounds its logarithm base…
A: Dear Student, As no language is mentioned , I am implementing the function in c++.
Q: Write a function called has_duplicates that takes a string parameter and returns True if the string…
A: alphabet="abcdefghijklmnopqrstuvwxyz" test_dups =…
Q: Write a generator expression G that produces the sequence of positive integers k in the range 1 < k…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.…
Q: By the "n queens problem" we mean the problem of placing n queens on an nXn “chessboard" in such a…
A: The ask is to find the number of solutions for nXn queens problem, using dynamically allocated…
Q: In python I have N unique coupons that are included in boxes of the cereal being sold. A consumer…
A: All the lines included after the #(hash) are python comments.To print the N unique coupons:for loop…
Q: Trace the function f as demonstrated in class for the function call f(3, 2): void f(int x, int y) {…
A: Here in this question we have given a c++ code segment and we have asked to trace the following code…
Q: Write a function can_write(letters, word) that returns True if the word of argument word can be…
A: Step 1 : Start Step 2 : Define the function can_write() which accepts 2 strings as parameter. Step 3…
Q: /* Write a function `coinProblem` that takes * 3 arguments: N, M and K; and solves following *…
A: PROGRAM EXPLANATION: Include the header file. Define a function coin problem(), this function will…
Q: Write a function decimal_to_binary(decimal_number) that takes in a non-negative integer and returns…
A: According to the given question, the proper solution is given below:
Step by step
Solved in 2 steps
- so i keep getting some seg fault issue due to the realloc in my program. I'm reallocing an array of layer_t structs, which is in a function to add an empty cake layer that's being called by another function layer_t add_fresh_layer (cake_t *cake) ( (...) cake->layers= realloc(cake->layers, sizeof(layer_t) * cake->layer_height * 2); (...) } int add_filling_layer (cake_t *cake){ for (int i = 0; i < cake->cake_height; i++) { layer_t *layer = &cake->layers[i]; (...) for (j = 0; layer->ingred[j] != NULL; j++) { char *ingredients = layer->ingred[j];] (...) for (k = 0; k < bake->layer_count; k++) { (...) } if (...) { (...) layer_t *filling = add_fresh_layer(bake); (...) } } }} I know that the realloc is causing the address to change while the pointer for cake->layers[i] remains the same. And i know the fix here is super simple, but I can't for the life of me remember what it isWrite a function in c++ is ordered that takes an integer array and its size as parameters and returns true if the array elements are ordered in nondecreasing order and returns false if not. For example, integers in {10,0,1,1,5,1009} are ordered in nondecreasing order. On the other hand, integers in {1, 2, 3, 8, 4, 19} are not since 8 > 4Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient Greeks. Choose an integer n. This function will compute all prime numbers up to, and including, n. First insert all numbers from 1 to n into a set. Then erase all multiples of 2 (except 2); that is, 4, 6, 8, 10, 12, ... . Erase all multiples of 3, that is, 6, 9, 12, 15, ... . Go up to ?⎯⎯√n. The remaining numbers are all primes. Make sure that you use functions in your solution, including a main function. Define def sieveOfEratosthenes(n) that receives the maximum value and returns a list of all prime numbers less than or equal to this value in main() print the list of prime numbers.
- I just need the method they are asking for Write a recursive function that takes a start index, array of integers, and a target sum. Your goal is to find whether a subset of the array of integers adds up to the target sum. The start index is initially 0.A target sum of 0 is true for any array. Examples: subsetSum(0, {2, 4, 8}, 10) -> true public boolean subsetSum(int start, int[] nums, int target) { }Implement function rotate that takes a string argument s and an integer argument n, and rotates the string s to the left by n times. For example, the code char s[] = "systems"; rotate(s, 3); will change s into "temssys", while the code char t[] = "abcd"; rotate(t, 1); will change t into "bcda". Restrictions: printf and strlen are the ONLY C library functions that you can use in the implementation. void rotate(char *w, int j)The goal is to rewrite the function, below, such that passes in a different list of parameters, particularly eliminating the need to pass low and high for each recursive call to binary_search. defbinary_search(nums,low,high,item): mid=(low+high)//2iflow>high:returnFalse #The item doesn't exist in the list!elifnums[mid]==item:returnTrue# The item exists in the list!elifitem<nums[mid]:returnbinary_search(nums,low,mid-1,item)else:returnbinary_search(nums,mid+1,high,item) The new function should be prototyped below. The number of changes between the given version, and the one requested is not significant. defbinary_search(nums,item):pass# Remove this and fill in with your code Tip: If you consider that high and low are used to create a smaller version of our problem to be processed recursively, the version requested will do the same thing, just through a different, more Pythonic technique.
- Write a function/ program that produces the following: int findDifference(const string a1[], int n1, const string a2[], int n2); Return the position of the first corresponding elements of a1 and a2 that are not equal. n1 is the number of interesting elements in a1, and n2 is the number of interesting elements in a2. If the arrays are equal up to the point where one or both runs out, return the smaller of n1 and n2. Notwithstanding each function's behavior described below, all functions that return an int must return −1 if they are passed any bad arguments (e.g. a negative array size, or a position that would require looking at the contents of an element past the last element we're interested in). Unless otherwise noted, passing 0 to the function as the array size is not itself an error; it merely indicates the function should examine no elements of the array. Here's an example: string cast[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" }; string roles[4] = { "samwell",…1. def f(x):"""Evaluates function `f(x) = x^2 - 15 \sin(x * \pi/3)`Parameters----------x : array_likeInput(s) to the functionReturns-------out : ndarrayFunction `f`, evaluated at point(s) x"""# your code here 2. def grad_f(x):"""Evaluates gradient of a function `f(x) = x^2 - 15 \sin(x * \pi/3)`Parameters----------x : array_likePoint(s) at which gradient should be avalueatedReturns-------out : ndarrayGradient of the function `f` evaluaed at point(s) x"""# your code here # TEST 1. f(x)assert f(0.) == 0.assert np.allclose(f(np.array([2.5, 7.5])), np.array([-1.25, 41.25])) assert np.allclose(f(np.arange(-10, 10, 1)), np.arange(-10, 10, 1)**2 - 15*np.sin(np.pi/3*np.arange(-10, 10, 1)))x_min = 1.33668375assert np.allclose(f(x_min), -12.9944407) # TEST 2. grad_f(x)assert np.allclose(grad_f(0.), -15.7079)assert isinstance(grad_f(0.), float) assert np.allclose(grad_f(0), - 5*np.pi*np.cos(0)), 'Gradient at point 0 is wrong'assert np.allclose(grad_f(np.arange(-10, 10, 1)), 2*np.arange(-10,…Write pseudocode for a function Det-Quicksort(A, p, r) that receives array A[1..n], and indices p and r. The function should sort the subarray A[p..r] recursively (meaning you should call itself). You can also use a function LinearSearch(A, p, r, v) that searches subarray A[p..r] for an element of value v and return its index (in case it exists) in O(r − p) time. (Just to give you something to compare to, the solution has 8 lines.)
- In Kotlin A. Write a function lengthGreaterThan() with an expression body that takes a String s and an Int n and returns true if the String is at least n characters long. Then revise the function so that it can accept null values. If it receives null as the parameter, it should return false. B. Write a recursive function with an expression body that takes a list of nullable Strings and and Int an returns a list of just the Strings from the original list for which the function you wrote in the first part returns true C. Get the same result as in part B by using filter()Write the following three functions: a) The function gets an array A of length n of ints, and a boolean predicate pred. It returns the smallest index i such that pred(A[i])==true.If no such element is not found, the function returns -1.int find(int* A, int n, bool (*pred)(int)); b) The function gets an array A of length n of ints, and a function f. It applies f to each element of A.void map(int* A, int n, int (*f)(int)); c) The function gets an array A of length n of ints, and a function f. The function f gets 2 ints and works as follows: Start with accumulator = A[0] For i=1...length-1 compute accumulator=f(accumulator, A[i]) Return accumulator For example, if f computes the sum of the two inputs, then reduce() will compute the sum of the entire array.int reduce(int* A, int n, int (*f)(int,int));Implement the following functions in the same application in C#: 1. Given a number (integer) N (greater than 1). Implement a Fibonacci sequence of length N. (Function name ComputeFibonacciSequence )ComputeFibonacciSequence receives N.2. Given a list L with n numbers (integers), implement a function that returns whether that list is even prone or not (i.e.: the number of even numbers in the list must be higher than that of the odd numbers.) (Function name ComputeEvenProne) - Return 1 if the list is even prone, return 0 if it is not.ComputeEvenProne receives L.