Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following function: int fives (int n) {if (n%5 == 0) return 0; else

ID: 3808155 • Letter: C

Question

Consider the following function: int fives (int n) {if (n%5 == 0) return 0; else return 1;} a. What is returned to answer if main calls: int answer = fives(15); _____ b. What is returned to answer if main calls: int answer = fives(26); _____ c. What is returned to answer if main calls: int answer = fives(ceil(squareroot (62.5))); _____ Write a value-returning function to calculate the root of a quadratic equation: root = -b +/b^2 - 4ac/2a given a, b, c are the parameters. Show a sample call in main to this function. Write a void method to calculate the area (1/2bh) and hypotenuse/h2 + b2 of a right triangle, given the base and height in parameters, and return both answers to main by reference. Show a sample call in main to this function.

Explanation / Answer

9.) (6)

                (a) In main we have: int answer = fives(15);

                                Now 15%5 = 0

                                So the condition if(n%5 == 0) is evaluated to true because 0 = 0

                                So the return value is 0.

                                Therefore answer = 0.

                (b) In main we have: int answer = fives(26);

                                Now 26%5 = 1

                                So the condition if(n%5 == 0) is evaluated to false because 1 != 0

                                So the return value is 1.

                                Therefore answer = 1.

                (c) In main we have: int answer = fives(ceil(sqrt(62.5)));

                                sqrt(62.5) = 7.90

                                ceil(7.90) = 8

                                Now 8%5 = 3

                                So the condition if(n%5 == 0) is evaluated to false because 3 != 0

                                So the return value is 1.

                                Therefore answer = 1.

10.) (7) In main : float a, b, c;

float root= rootCalculating(a, b, c);

                                Function starts:

                                float rootCalculating(float a, float b, float c)

{

float rootValue = (-b + sqrt(pow(b,2)- 4*a*c))/(2*a)

                                /*(Don’t forget to import math library) */

                                                Return rootValue;

                                }

11.) (7) In main:

                                float b,h;

Triangle(b,h); function call from main to calculate the area of the triangle.

                               Function starts:

`               void Triangle(float b, float h)

                                {

                                                float AreaOfTriangle= (b*h)/2;

                                                float hypotenuses = sqrt(pow(h,2) + pow(b,2))

                                                printf(“Area of Triangle is: %f”, AreaOfTriangle);

                                                printf(“Hyptenuses is: %f”, hypotenuses);

/* this is in C language */

                                }                                

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote