Consider the following C++ function. int mystery(int num1, int num2){if (num1 > 0){for (int i = 1; i <= num1; i++)num2 = num2 * i;return num2;}else if (num2 > 0){for (int i = 0; i <= num2; i++)num1 = num1 + i;return num1;}return 0;}What is the output of the following statements?a. cout << mystery(4, -5) << endl;b. cout << mystery(-8, 9) << endl;c. cout << mystery(2, 3) << endl;d. cout << mystery(-2, -4) << endl;
Q: Write a C++ program that would implement the function called filterString which accepts a string s…
A: Filtering number from given string using c++
Q: Write a C++ program that would implement the function called filterString which accepts a string s…
A: The required code for the Cpp function filterString is coded in the next step by using a for loop.
Q: Define a function in C language that takes two integers p and q as the parameters and returns the…
A: Use if else to satisfy this program need. define myFunc(int p,int q) If(p==q) return p*q else…
Q: Exercise : Write a C++ program that computes and returns: • the smallest positive integer (n) for…
A: Program Approach: Including a necessary header file Defining method compute Declare variable 0 to n…
Q: Write a C++ function that accepts a double typed number and return back the fractional part of the…
A: C++ Code for as par your requirements: it prints only fractional parts. #include <iostream>…
Q: A) Consider the programming language Lisp. Write a Lisp function that calculates the following…
A: Writing function: The macro named defun is used for defining functions. The defun macro requires…
Q: Write in C Language Description F(x) = x + 1 G(x, y) = x + y Please write a program to…
A: /* C program to calculate the value of composite of F and G */ #include<stdio.h> int F(int x)…
Q: Write a C program that creates a security access code from a social security number entered by a…
A: // stdio.h is the C standard library it is a header file stdio.h which stands for standard…
Q: Write a c++ program: Write a function named convertToLowestTerms that inputs two integer parameters…
A: Program code: //include required header files #include<iostream> using namespace std;…
Q: Write a C++ program that computes the equivalent resistance of a purely series and purely parallel…
A: Required c++ code with class and object Provided below : Formula to used : Equivalent Series…
Q: Data Charges Rates, in Megabit(mb) Usage(n), in Gigabit(gb) 0.0 5.0 On a piece of paper, write a…
A: The question wants us to write a C plus code for computing the total amount using a given amount of…
Q: Write a C++ program to compute the value of S using function, where the value of n) = X /- ( X/3! +…
A: Given:
Q: Write a function in C++ to take input an integer parameter n and return whether the number is a…
A: Write a function in C++ to take input an integer parameter n and return whether the number is a…
Q: Write a C++ program that includes the following function: a boolean function with the name of…
A: #include<iostream>using namespace std;//boolean function to check number is even or odd//if…
Q: Write a c program that calculates the potential energy of 3 charges q1=1, q2=2, q3=3 located at…
A: please do upvote for my efforts thanks! answer: code #include…
Q: Write a program function (in any programming language) that will find and add every alternative…
A: Step 1: Note :-I am writing the program in c++ programming language:- Introduction:- Prime number is…
Q: 12. Consider the recursive function int gcd( int a, int b) int gcd( int a, int b){ if (b > a)…
A: Recursive function: It is a function that calls itself during execution. The number of invocations…
Q: Given a string S of characters, write a C function countAndPrint that prints on the screen all the…
A: //C program #include<stdio.h> #include<string.h> //count and print substrings void…
Q: Write a program in C++ , that finds solution (roots) of quadratic equation, allow user to input as…
A: Program: //Include necessary header files #include <iostream> #include <cmath>…
Q: Programming in C What's wrong with this function? void test(max) { int max, i; for (i = 0 ; i < max…
A: Error Correction Reason void test(max) void test(int max) In C programming the parameter of…
Q: Write a C++ program that would implement the function called filterString which accepts a string s…
A: Here I have defined the function filterString(). Inside the function, I have looped over the string…
Q: Write a C++ program that would implement the function called filterString which accepts a string s…
A: Here I have defined the function named filterString(). In this method, I have looped over the string…
Q: Write a program in C++ to compute the total and average of six numbers( by using friend class &…
A: c++ program by using a friend class is as given below : #include<iostream> using…
Q: Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns…
A: #include<iostream> using namespace std; int smallestIndex(int list[], int listSize); int…
Q: Write a program (using c++ language) that has a class triangle with an overloaded function Area().…
A: Triangle.cs class Triangle:Shape public double S3 set }public override double…
Q: Here's the task in c program that I need. Instructions: Ask the user for a string input From…
A: Algorithm: Start Read a string s Iterate through the string from i=0 to s[i]!='\0' If…
Q: Write a C++ program that computes and returns: • the smallest positive integer (n) for which…
A: The instructions are provided by the programmer according to the requirement using the programming…
Q: The following C function evaluates the polynomial of degree n at point x P(x) = ao a1 x + a2 x² + …+…
A: Note: Since your question contain multiple question but we can answer only one question at a…
Q: Investigate the math library in C and write a function in C called mather which takes a double value…
A: Before going to code we have to add the math library in our header file. Syntax:…
Q: Define a function in C++ language that takes an integer n as the parameter and then multiplies it by…
A: Define a function in C++ language that takes an integer n as the parameter and then multiplies it by…
Q: Write a c++ program that asks the user to enter a number and then prints all the divisors of that…
A: #include <iostream> using namespace std; int main(){ int num = 0; cout<<"\n Enter…
Q: Write java function that takes three numbers and returns max from three using ternary operators…
A: GIVEN: Write java function that takes three numbers and returns max from three using ternary…
Q: Write a recursive function definition in C that will calculate the sum of the first n odd integers…
A: Here is your recursive program in C , with well defined comments!
Q: In C programming Mathematically, given a function f, we recursively define fk(n) as follows: if k…
A: Solution: Given data given a function f, we recursively define fk(n) as follows: if k = 1, f1(n) =…
Q: implement the following tasks using recursive functions in C programming: Summation of the…
A: Using recursive function in c programing Summation of the integers 1,2,3,4....n Factorial function…
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: Write the definition of a bool function named BooleanMode () whose header is bool BooleanMode (bool…
A:
Q: write a C program that has the following statements int a,b; a = 10; b = a + fun(); printf("With…
A: I have given an answer in step 2.
Q: Write a C# class Factors having function static int CountOddFactors(int n) that would return count…
A: Task :- Write a C# program to count the number of odd factors for given number. C# program :-…
Q: Write a function in C++ that takes two strings as parameters and return a boolean value. Function…
A: Get the lengths Get the remainders to check whether lengths are even or odd Check whether remainders…
Q: Write a C++ program to compute the value of S using function, where the value of n) = X /1!- ( Xy3!…
A: PROGRAM INTRODUCTION: Include the required header files. Start definition of the method to…
Q: Write the C equivalent “train” function #void train(int*A, int*B, int*C, int k) train: add…
A: I have decoded the MIPS code and written all 11 instructions with a meaning along with the MIPS…
Q: Write a complete C++ program that contains the integer functions (main, funx and funy). The main…
A: Input to the code : The integer k Output of code : Value evaluated by passing k in different…
Q: Consider the following recursive function: void recurse(int num) { if (num == 0)…
A: EXPLANATION: “Yes”, the given call recurse (-2) us a valid call. This calls the recurse function…
Q: write a c++ program that asks user to enter a number and then print the number that is maximum time…
A: #include<iostream> using namespace std; int main(){ int n, x, max_count=0; cout…
Q: Please help me with question b to find the running time. Thank you.
A: For function F1 the number of steps assuming only if branch: T(1) = 1 T(n) = 1 + T(n/2) Hence by…
Q: //write a program in C++ that reads ten positive random numbers and finds the largest d number in it…
A: code #include <iostream>using namespace std;void print_odd_high(int x[]){ int max = 0;…
Q: .The following is the C code that you need to implement for this lab: uint8_ t f(uint8_tn)…
A: Hey there, I am writing the required solution based on the above given question. Please do find the…
Q: Write a C++ program that converts from 24-hour notation to 12-hour notation. For example, it should…
A: Below program will read the input from the user and stores into variable. Program contains three…
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…
Consider the following C++ function.
int mystery(int num1, int num2)
{
if (num1 > 0)
{
for (int i = 1; i <= num1; i++)
num2 = num2 * i;
return num2;
}
else if (num2 > 0)
{
for (int i = 0; i <= num2; i++)
num1 = num1 + i;
return num1;
}
return 0;
}
What is the output of the following statements?
a. cout << mystery(4, -5) << endl;
b. cout << mystery(-8, 9) << endl;
c. cout << mystery(2, 3) << endl;
d. cout << mystery(-2, -4) << endl;
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- Implement in C Programming 6.6.3: Function with loop: Shampoo. Write a function PrintShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done.". End with a newline. Example output with input 2:1: Lather and rinse. 2: Lather and rinse. Done. Hint: Declare and use a loop variable. #include <stdio.h> /* Your solution goes here */ int main(void) { int userCycles; scanf("%d", &userCycles); PrintShampooInstructions(userCycles); return 0;}In C++ Consider the following recursive function (Chapter 17, #9, modified) void recFun(int x) { if (x > 10) { recFun(x / 10); cout<< x % 10; } else cout<< x; } How can the code be modified so that the sum of all digits is printed?Write a C++ program that includes the following function: a boolean function with the name of "evenorodd" that tests a number to see whether it is even or odd. your program should do the following in each iteration: ask the user to enter a number and each time by calling "evenorodd" function determines if the number is even or odd? then ask the user: "Do you want to continue?" if the answer is "Y" or "Yes", then repeat the process
- Write a C++ function using recursion that returns the Greatest Common Divisor of two integers. The greatest common divisor (gcd) of two integers, which are not zero, is the largest positive inteteger that divides each of the integers. The code should follow the exact function declaration: int GCD(int number1, int number2);Write a C++ program that would implement the function called filterString which accepts a string s that contains numbers and letters mixed up. The function must return an integer corresponding to the numbers in s in the order that they appear. If there are no numbers in s, the function should return 0. TEST CASES: filterString(‘123’) = 123 filterString(‘abc’’) = 0 filterString(‘aa 112 3dd’) = 1123 ASSUMPTIONS Assume that all the inputs are strings (no need for try-catch method) Please take note of test cases and assumption. Thank you!Draw Flowchart of this program // C# program for implementation // of Lagrange's Interpolation using System; class GFG { // To represent a data point // corresponding to x and y = f(x) class Data { public int x, y; public Data(int x, int y) { this.x = x; this.y = y; } }; // function to interpolate the given // data points using Lagrange's formula // xi corresponds to the new data point // whose value is to be obtained n // represents the number of known data points static double interpolate(Data []f, int xi, int n) { double result = 0; // Initialize result for (int i = 0; i < n; i++) { // Compute individual terms // of above formula double term = f[i].y; for (int j = 0; j < n; j++) { if (j != i) term = term * (xi - f[j].x) / (f[i].x - f[j].x); } // Add current term to result result += term; } return result; } // Driver code public static void Main(String[] args) { // creating an array of 4 known data points Data []f = {new Data(0, 2), new Data(1, 3), new Data(2, 12), new Data(5,…
- Write a program in C language that implements a simple hand calculator. The followings arithmetic functions are available on the calculator: addition, subtraction, multiplication, division, cosine, sine and tangent. The result of the function must have the same number of digits of precision as the highest precision operand of the function. An example of the program behavior is shown below. > 8.91 + 1 = 9.91 > 9.61*3.11 = 29.8871 > cos(3.14152759) = 0.99849715Write a C program that creates a security access code from a social security number entered by a user as follows: Using a recursive function it adds all of the digits of the social security number and then using a regular function gets the square number of the sum and displays it. The access code displayed should be initialized as an integer number but using type casting is displayed as a floating number.Implement in C Programming 6.25.1: LAB: Fibonacci sequence The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the previous two, for example: 0, 1, 1, 2, 3, 5, 8, 13. Complete the Fibonacci() function, which has an index n as a parameter and returns the nth value in the sequence. Any negative index values should return -1. Ex: If the input is: 7 the output is: Fibonacci(7) is 13 Note: Use a for loop and DO NOT use recursion. #include <stdio.h> int Fibonacci(int n) { /* Type your code here. */} int main(void) { int startNum; scanf("%d", &startNum); printf("Fibonacci(%d) is %d", startNum, Fibonacci(startNum)); return 0;}
- Implement a recursive C++ function which takes two integers num and den as arguments and returns theinteger quotient that will result when num is divided by den. The prototype of your function should be:int quotient (int num, int den)Hint: Think about repeated subtractionWrite in C Language Description F(x) = x + 1 G(x, y) = x + y Please write a program to calculate the value of composite of F and G Input Input will be the composite of F and G. The parameter of F and G are integer only. Output An integer represent the value of function. Sample Input 1 F(G(1,F(3))) Sample Output 1 6Write a C program where you have to take 2 numerical inputs and 1 input for operator {the operator input has to be either ‘+’, ’-’, ’*’). Depending on some comparisons, you need to carry out three operations: addition ( + ), subtraction ( - ) and multiplication ( * ). Each of these operations will be implemented in separate methods. (i) If the first number is greater than the second number, do subtraction and print the result. (ii) If the first number is less than the second number, do addition and print the result. (iii) If the second number is equal to the second number, do multiplication and print the result