Question

In: Computer Science

Design and implement a function with two input parameters, A and B. The functions then calculates...

Design and implement a function with two input parameters, A and B. The functions then calculates the result of the floor division of A over B (A//B). You are not allowed to use the floor division operator. Look at here: https://simple.wikipedia.org/wiki/Division_(mathematics) - For instance the function for 20 and 6 will return 3.

Solutions

Expert Solution

Explanation:-

To calculate Ceil without using ceil() a function is created and in that we will use '/' operator between the 2 values and it will give us the ceil value.

Code is as follows:-

#include <iostream>

#include <bits/stdc++.h>             // Header Files

using namespace std;

int calculateCeil(int a, int b) {              // Function accepting two args. and calculating Ceil without using ceil()

    int ans = a/b;                            // Variable storing the ceil value

    return ans;

}

//Driver Function

int main() {

    int a = 20;

    int b = 6;

    int ans = calculateCeil(a,b);        // Calling the function to calculate ceil value and passing a & b as argument

    cout<<"Ceil Value is : "<<ans;              // Printing the ceil value

}

Output:-

   


Related Solutions

- Design and implement a function with no input parameters. The function keeps receiving a number...
- Design and implement a function with no input parameters. The function keeps receiving a number from input (user) and adds the numbers together. The application keeps doing it until the user enter 0. Then the application will stop and print the total sum and average of the numbers the user had entered.
Read the function definitions of the two functions: “compute_st_ave” and “compute_quiz_ave”. Write a function that calculates...
Read the function definitions of the two functions: “compute_st_ave” and “compute_quiz_ave”. Write a function that calculates the average of student averages. (Student averages are stored in st_ave [5] array). Include a statement to print this average on the screen. Declare this function above the “main” function where other functions are declared. In the main program, invoke this function. //Reads quiz scores for each student into the two-dimensional array grade //(but the input code is not shown in this display). Computes...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at...
Write a python code to Design and implement a function with no input parameter which reads...
Write a python code to Design and implement a function with no input parameter which reads a number from input (like 123). Only non-decimal numbers are valid (floating points are not valid). The number entered by the user should not be divisible by 10 and if the user enters a number that is divisible by 10 (like 560), it is considered invalid and the application should keep asking until the user enters a valid input. Once the user enters a...
Design and implement a function which has one input parameter which is a number which is...
Design and implement a function which has one input parameter which is a number which is greater than 50, called num. Then the function will create a dictionary whose keys are 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9. Then the function calculates the values for each of the above keys. The value for a key is all the numbers between 2 and input “num” that are divisible by the key. The function...
1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings...
1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings will each be ONE character and will represent a nucleotide. The list will be a nested int list representing a 4x4 score matrix. This function will return the value (int) from the nested int list at the location of the two referenced nucleotides. a. An example call to calculate_score would be calculate_score(“A”, “T”, score_matrix). If we look at the alignment score table in the...
Define a function named "find" that accepts two input parameters: "s "and "ch". "s" is an...
Define a function named "find" that accepts two input parameters: "s "and "ch". "s" is an object of the type "string" and "ch" is a character value with the default argument of 'A'. The function looks for the character "ch" in the string  "s" and displays all the indices of its occurrences on the screen. For example, if the caller sends the values of "ABCDBGAB" and 'B' to the function for the parameters "s" and "ch", respectively, the function displays the...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates...
Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define (h x) (sub1 (add1 x))). You will need to use...
Use Verilog to design and implement a function as  c = c+∑b*ai, i is from 1 to...
Use Verilog to design and implement a function as  c = c+∑b*ai, i is from 1 to 8. Here ai is stored in a SRAM with width as 16 and depth as 8 (8 rows of 16‐bit data), and b is stored in a 16‐bit register. c is initialized as 0.
Code an Entire Piston Design in MATLAB or C with the given input parameters are Crank...
Code an Entire Piston Design in MATLAB or C with the given input parameters are Crank Length , crank radius, crank angle , maximum explosion pressure (Pmax) , bore , stroke Assume any for necessary values to get the output The output should include Piston clearance Top Skirt bottom Skirt crown thickness skirt thickness piston ring dimensions gudegeon pin dimensions
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT