Write code for a function with the following prototype:
/* Addition that saturates to TMin or TMax */
int saturating_add(int x, int y);
Instead of overflowing the way normal two’s-complement addition does, saturating addition returns TMax when there would be positive overflow, and TMin when there would be negative overflow. Saturating arithmetic is commonly used in
Your function should follow the bit-level integer coding rules (page 128).
Trending nowThis is a popular solution!
Chapter 2 Solutions
Computer Systems: Program... -Access
Additional Engineering Textbook Solutions
Experiencing MIS
Digital Fundamentals (11th Edition)
C How to Program (8th Edition)
Starting Out With Visual Basic (8th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Artificial Intelligence: A Modern Approach
- Write C code that contains a function called triangle_generator that outputs a triangle wave at a specified frequency (in hertz) using a specified sample rate (in hertz), and for a specified time duration (in seconds). These parameters are float type. The output you generate are floating point numbers between -1 and 1, one number per output line. The math trig functions in C use radians while all the specifications here are in hertz (cycles per second). One hertz is 2*Pi radians.arrow_forwardDefine a function calc_pyramid_volume() with parameters base_length, base_width, and pyramid_height, that returns the volume of a pyramid with a rectangular base. calc_pyramid_volume() calls the given calc_base_area() function in the calculation.Relevant geometry equations:Volume = base area x height x 1/3(Watch out for integer division).Sample output with inputs: 4.5 2.1 3.0 Volume for 4.5, 2.1, 3.0 is: 9.45 def calc_base_area(base_length, base_width): return base_length * base_width ''' Your solution goes here ''' length = float(input())width = float(input())height = float(input())print('Volume for', length, width, height, "is:", calc_pyramid_volume(length, width, height))arrow_forwardGiven a number N (>0). Write a c++ function to find a digit whose frequency is maximum.Function Prototype: void maxFrequencyOfNumber(int num,int & digit, int &maxFreq);Examples:Input: N = 1122322 Output: digit: 2 Max Frequency:4Input: N = 1002023 Output: digit: 0 Max Frequency:3Note: For duplicate max frequency display any digit. For Example:N=10022Output: digit: 0 Max Frequency 2 //OROutput: digit: 2 Max Frequency 2Note: Take input and display output in main function.Solve the question without using arrays.arrow_forward
- Given a number N (>0). Write a c++ function to find a digit whose frequency is maximum.Function Prototype: void maxFrequencyOfNumber(int num,int & digit, int &maxFreq);Examples:Input: N = 1122322 Output: digit: 2 Max Frequency:4Input: N = 1002023 Output: digit: 0 Max Frequency:3Note: For duplicate max frequency display any digit. For Example:N=10022Output: digit: 0 Max Frequency 2 //OROutput: digit: 2 Max Frequency 2Note: Take input and display output in main function.arrow_forwardWhich statements is not true about a parameter of a function that is passed-by-reference. A. the formal parameter is an alias of the real parameter B. the reference to the real parameter is passed to the formal parameter C. changing the formal parameter inside the function causes change to the real parameter D. the real parameter cannot be a constant and has to be a variable E. None of above Using a 3-bit cell to store unsigned integers, what is the largest integer that can be stored? A. 15 B. 3 C. 16 D. 8 E. 7arrow_forwardConsider the following function someFunc::Integer -> Integer -> Integer -> Integer someFunc x y z = x *(y + z) Prove that someFunc a b c = sumFunc a c barrow_forward
- Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4.Write a function that takes an integer n and return all possible combinationsof its factors.Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4.Examples:input: 1output:[]input: 37output:[]input: 32output:[ [2, 16], [2, 2, 8], [2, 2, 2, 4], [2, 2, 2, 2, 2],""".arrow_forwardWrite a procedure is_little_endian that will return 1 when compiled and run on a little-endian machine, and will return 0 when compiled and run on a big-endian machine. This program should run on any machine, regardless of its word size. For this problem, write a function instead and call the function by sending it an integer. C program.arrow_forwardDefine a function calc_pyramid_volume() with parameters base_length, base_width, and pyramid_height, that returns the volume of a pyramid with a rectangular base. calc_pyramid_volume() calls the given calc_base_area() function in the calculation.Relevant geometry equations:Volume = base area x height x 1/3(Watch out for integer division).Sample output with inputs: 4.5 2.1 3.0 Volume for 4.5, 2.1, 3.0 is: 9.45 python def calc_base_area(base_length, base_width): return base_length * base_width ''' Your solution goes here ''' length = float(input())width = float(input())height = float(input())print('Volume for', length, width, height, "is:", calc_pyramid_volume(length, width, height))arrow_forward
- Write a “C” program to find the summation of the following series: 1/8+ 1/27 + 1/64 + 1/125 + 1/216 + .............. + 1/(n+1)3Hint: To compute the power of a number, you can apply basic mathematics multiplications equations or use the pow() function computes the power of a number.The basic mathematics multiplications equations:For example: [In Mathematics] x4 = x*x*x*x [In programming]The pow() function:The pow() function takes two arguments (base value and power value) and, returns the power raised to the base number.For example, [In Mathematics] xy = pow(x, y) [In programming]The pow() function is defined in <math.h> header file (#include<math.h>)arrow_forwardWrite a program to calculate the B power of Afor non-negative value of B. A" = Ax Ax A...xA Without using the pow(A,B) function.arrow_forwardWrite a C++ function factorial that takes an integer, n, and returns the value of n factorial (a.k.a., n!): When n is positive, n! = 1 * 2 * 3 * ... * n. For example, 5! = 1 * 2 * 3 * 4 * 5 = 120. When n is zero, n! is defined to be 1. When n is negative, n! is undefined. You may assume that the parameter n will not be negative for this problem.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr