Write and test the “digit" function: Function Prototype: int digit(int n,int k) This function returns the kth digit of the positive integer n. For example, if n is the integer 29,415, then the call digit(n,0) would return the digit 2, and the call digit(n,2) would return he digit 4. Examples:
Q: n Matlab: Write a function that takes a month, day, and year as inputs and returns the number of…
A: a function that takes a month, day, and year as inputs and returns the number of days that have…
Q: Write a function which will take 4 arguments. They are: starting value(inclusive) ending…
A: As no programming language is mentioned, so i am using python to code. In step 2, you will the…
Q: Write and test the “digit” function: Function Prototype: int digit(int n,int k) This function…
A: Python programming language is the high-level interpreted programming language, It's also used to…
Q: The function doit(a,b,c,d) is a function that multiplies the smallest of its integers arguments by…
A: C Program: #include <stdio.h> //function prototypevoid doit(int,int,int,int); int main() {…
Q: Write the function int isEven (int x); that returns 1 if x is an even number; otherwise, it returns…
A: please check the step 2 for required c++ code and step 3 for output.
Q: 4-Write the definition of function with two parameters (start and end) of type int. The function…
A: 4. // Function Definition void PrintNaturalNumbers(int start,int end){ int temp = start;…
Q: 13- Write a function that takes a positive integer "n" as the function parameter and returns True if…
A: Take a number from user declare a temp variable that is set to False check if the number is greater…
Q: python Define stubs for the functions get_user_num() and compute_avg(). Each stub should print…
A: Step 1:- Given:- Define stubs for the functions get_user_num() and compute_avg(). Each stub should…
Q: .Write a function absolute(x) that prints the absolute value of x
A: abs(x)- This method returns absolute value of x - the (positive) distance between x and zero.
Q: Given the following functions: void sum(int a, int b) { cout << a+b << "\n"; } int sum(int a, int b)…
A: Function overloading is the concept when multiple functions of same name is used for multiple tasks.…
Q: Write a function to check the prime number. Your function takes one parameter (input), a natural…
A: code in python- def prime(n): for i in range(2,n): if (n%i) == 0: return False return True…
Q: Templatize the fibonacci( ) function on the type of value that it produces (so it can produce long,…
A: template<int N, typename T = int>struct fibonacci { static constexpr T value =…
Q: A number, a is a power of b if it is divisible by b and a/b is a power of b. Write a function called…
A: Since the programming language is not mentioned , I have done the code in python. Algorithm :…
Q: True or false? A call to a None function is always a statement itself, but a call to a…
A: True or false? A call to a None function is always a statement itself, but a call to a…
Q: Write a function that has the following prototype:
A: Need to include malloc.h in the header Ask the user to input no. of rows and columns Create a…
Q: 2. Given the following function A(a, b), what does A(8, 3) return? 1 function A(a, b) 2 if b = 0 3…
A: code:
Q: 2. Implement the following functions: i) ii) void hollowTriange (int height) void pyramid (int…
A: Given:
Q: Write overloaded function calculate() with following function definitions. void calculate(int x, int…
A: Given: Write overloaded function calculate() with following function definitions.void calculate(int…
Q: A function can return another function.
A: YES
Q: def is_teenager(age: int) -> bool: "* "Return True iff age represents a teenager between 13 and 18…
A: According to the Question below the solution: Output:
Q: Question 4: Total Price Implement the function total_price , which takes in a list of prices of…
A: logic:- define function set total=0 iterate the list using for loop. Set tax=0 if i>=20…
Q: Write a function subtract for the rational type which puts the result in simplest form. Write a…
A: As there is no particular language mentioned I am doing this using C++ code. Subtraction function:…
Q: 9. Do Programming Exercise 3 from Chapter 5 using a function grade(score) that returns the letter…
A: Functions in python: Functions provide a way to break problems or processes down into smaller and…
Q: Assignment 1: Write a function getFactorial() that will return the factorial of an integer. Call…
A: Since the programming language is not mentioned so I have used the C++ programming language.…
Q: Write another version of the checkeven function. This version receives 3 integer variables and…
A: As programming language is not specified, the function is written in python
Q: Write the definition of the function add, which takes two integer parameters and returns the sum of…
A: Introduction: Here we are required to write the definition of the function add, which takes two…
Q: Write the prototype for your function. Write a call for your function.
A: Required:
Q: Write two or more function, parameters and arguments that generates a random license plate. Your…
A: The code for the above given question is given below:
Q: Exercise 6: Area of a Circular Sector Write a function area_of_circular_sector() which • takes 2…
A: In this program question using python We have to calculate area of circular sector using two…
Q: Write a function named sumDivisors that accepts an integer as its parameter and returns the sum of…
A: #note no programming language is mentioned so i was written my program in python def…
Q: Write two functions that implement the following conversions: a. Function celsius receives a…
A: Program: #include<bits/stdc++.h> #include <iostream> using namespace std; float…
Q: Write a function int largest(int a[],int n) that will find the largest int in the n ints in a.
A: Assembly code to find the largest number in the array: LXI H 2050 MOV C, M DCR C INX H MOV A, M INX…
Q: Write a function cube that returns the cube of the float given as argument (use multiplication,…
A: In step 2, you will get C++ code. In step 3, you can see the sample output.
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: What is wrong with the following function? int 3integer_add( int x, int y, int z) {…
A: void sum(int x, int y, int& z) The function sum takes three integer parameters, according to…
Q: Code the function multiplier(). //**** **** ******* k**** //The multiplier function takes 2 integer…
A: C++ program for multiplication using multiplier function. User has to enter two integer to be…
Q: Write a function num_digits that takes a number, and returns the count of digits in the number. For…
A: Here we need to count the number of digits, So, divide the number by 10 till it becomes 0 and the…
Q: Given the following functions: void sum(int a, int b, int total) { total = a+b; } int main() {…
A: Here in sum() function we are adding variable a and b and store its result in variable total. As…
Q: Write a function that checks whether an integer is an even digit or an odd digit integer using the…
A: Odd or Even: A certain variety is given conjointly the} task is to count even digits and odd digits…
Q: a- Write a program to pass two integer numbers as parameters to a function; this function is used to…
A: Here, Code instruction is given.
Q: Prompt: When someone calls you on the phone, he or she looks up your number in a phone book (a…
A: In the current situation we have 2 major steps: Lookup for the name (corresponding to number) Call…
Q: Rewrite the following function using just a single statement (which must be a return statement).…
A: Given: def thing(i, j): if i> 10: if j < 5 or i> 20: return False…
Q: 1)Write a function in Python that takes four parameters a, b, c and n and then checks to see if…
A: python code is given below:
Q: Homework: Is Even Let's write another simple function. Declare and implement a function called is…
A: I have provided the answer based on Java Programming. Detailed comments are included for a better…
Q: Write a function fune/2 which has two arguments and returns true, if the two arguments are equal,…
A: Please refer below code and output screenshot: In below code fune__2 implies fune/2: Language used…
Q: نقطتان )2( If the function is called, such as fun_x(13,2), the return value of the * function would…
A: Introduction: A default argument refers to the value that is assigned while declaring the function.…
Q: dangerous function below throws an error if it is given a certain integer number a. That is, the…
A: Program - def dangerous(a): z = 9302648 x = z + a return a result = dangerous(66/0)print("The…
C++ program
Step by step
Solved in 2 steps with 1 images
- (Numerical) Heron’s formula for the area, A, of a triangle with sides of length a, b, and c is A=s(sa)(sb)(sc) where s=(a+b+c)2 Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of sand[s(sa)(sb)(sc)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A=1. The value of A should be returned by the function.Mark the following statements as true or false: a. To use a predefined function in a program, you need to know only the name of the function and how to use it. (1) b. A value-returning function returns only one value. (2, 3) c. Parameters allow you to use different values each time the function is called. (2, 7, 9) d. When a return statement executes in a user-defined function, the function immediately exits. (3, 4) e. A value-returning function returns only integer values. (4) f. A variable name cannot be passed to a value parameter. (3, 6) g. If a C++ function does not use parameters, parentheses around the empty parameter list are still required. (2, 3, 6) h. In C + + , the names of the corresponding formal and actual parameters must be the same. (3, 4, 6) i. A function that changes the value of a reference parameter also changes the value of the actual parameter. (7) j. Whenever the value of a reference parameter changes, the value of the actual parameter changes. (7) k. In C++, function definitions can be nested; that is, the definition of one function can be enclosed in the body of another function. (9) l. Using global variables in a program is a better programming style than using local variables, because extra variables can be avoided. (10) m. In a program, global constants are as dangerous as global variables. (10) n. The memory for a static variable remains allocated between function calls. (11)Write the definition of a function that takes as input two decimal numbers and returns first number to the power of the second number plus second number to the power of the first number. (4)
- (Numerical) a. The following is an extremely useful programming algorithm for rounding a real number to n decimal places: Step 1: Multiply the number by 10n Step 2: Add 0.5 Step 3: Delete the fractional part of the result Step 4: Divide by 10n For example, using this algorithm to round the number 78.374625 to three decimal places yields: Step1:78.374625103=78374.625 Step2:78374.625+0.5=78375.125 Step3:Retainingtheintegerpart=78375Step4:78375dividedby103=78.375 Using this algorithm, write a C++ function that accepts a user-entered value and returns the result rounded to two decimal places. b. Enter, compile, and run the program written for Exercise 11a.(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x1,x2,x3,x4,andx5, then the mean is x=(x1+x2+x3+x4+x5)/5 and the standard deviation is: s=(x1x)2+(x2x)2+(x3x)2+(x4x2)+(x5x2)5 Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation.
- Write and test the “digit” function:Function Prototype: int digit(int n,int k)This function returns the kth digit of the positive integer n. For example, if n is the integer 29,415, then the call digit(n,0) would return the digit 2, and the call digit(n,2) would return the digit 4.Write and test the “digit” function: Function Prototype: int digit(int n,int k)This function returns the kth digit of the positive integer n. For example, if n is the integer 29,415 that is entered by user , then the call digit(n,0) would return the digit 2, and the call digit(n,2) would returnthe digit 4. do this only by using functions and loops. arrays are not allowed. example :Input: n = 29415 , k = 1 output: 9 Input: n = 2 , k = 1 output: index out of bound (return -1)Please help me with my homework, in computer programming as follows: A number, a is a power of b if it is divisible by b and a/b is a power of b. Write a function called is_power that takes parameters a and b and returns True if a is a power of b. Note: you will have to think of the base case.
- Write two functions that implement the following conversions:a. Function celsius receives a Fahrenheit temperature and returns its Celsius equivalent.b. Function fahrenheit receives a Celsius temperature and returns its Fahrenheit equivalent.Write a test program (main function) that uses celsius and fahrenhiet to print the following table.Celsius Fahrenheit | Fahrenheit Celsius40.0 104.0 | 120.0 48.8939.0 102.2 | 110.0 43.33...232.0 89.6 | 40.0 4.4431.0 87.8 | 30.0 -1.113. Find Relatively Prime Write a function to return a number that is relatively prime with the given number. /* return an integer that is relatively prime with n, and greater than 1i.e., the gcd of the returned int and n is 1 Note: Although gcd(n,n-1)=1, we don't want to return n-1*/int RelativelyPrime (int n) 4. Find Inverse Then implement the following function, which returns the inverse modulo, and test it.Note that you need to check whether a and n are relative prime before calling thisfunction. Recall that a and n are relatively prime means that gcd(a,n)=1, i.e., theirgreatest common divisor is 1. Also recall that the extended Euclidean Algorithm canfind the integer s and t for a and n such that as+nt=gcd(a,n), where s is the inverseof a modulo n. /* n>1, a is nonnegative *//* a<=n *//* a and n are relative prime to each other *//* return s such that a*s mod n is 1 */int inverse (int a, int n){int s, t;int d = ExtednedEuclidAlgGCD (n, a, s, t);if (d==1){return (mod (t,…Write two or more function, parameters and arguments that generates a random license plate. Your function should have approximately equal odds of generating a sequence of characters for an old license plate or a new license plate. Write a main program that calls your function and displays the randomly generated license plate.