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

This is activty from chapter 6 Function. 2. Write a function called week4 that t

ID: 3599698 • Letter: T

Question

This is activty from chapter 6 Function.

2. Write a function called week4 that takes a number as input and returns the square root of the number Try using the function. Try assigning a variable using a function call.

3. Do the function definitions have to appear in this order? What happens if we change the order? When is the square function function actually called?

4. Modifying parameters: What is the result? Why is this the result?

Why does the list modification work? What is different?

5. Specifications:

Do we need a return or is a void function acceptable? Could we technically do it either way?

What features do we have to use to accomplish this goal?

Explanation / Answer

//I have few doubts related to 4 i have written in that section please acknowledge me if valid

This is activty from chapter 6 Function.

2. Write a function called week4 that takes a number as input and returns the square root of the number Try using the function. Try assigning a variable using a function call.

#include<stdio.h>

#include<math.h>

//function prototype defined here

double week4(int);

//function declaration for week4 takes an input n

double week4(int n)

{

//calculating and returning square root of value

//using inbuild function

return sqrt(n);

}

int main()

{

//using function here

//calling and assinging the result to variable

double result = week4(9);

//displaying to console

printf("%.1f ",result);

return 0;

}

//OUTPUT : 3.0

3. Do the function definitions have to appear in this order? What happens if we change the order? When is the square function function actually called?

No matter the function definitions have different order as long as function prototype defined

in above code after the modification the order of function week4 and main will have same result as above

#include<stdio.h>

#include<math.h>

//function prototype defined here

double week4(int);

int main()

{

//using function here

//calling and assinging the result to variable

double result = week4(9);

//displaying to console

printf("%.1f ",result);

return 0;

}

//function declaration for week4 takes an input n

double week4(int n)

{

//calculating and returning square root of value

//using inbuild function

return sqrt(n);

}

//OUTPUT : 3.0

4. Modifying parameters: What is the result? Why is this the result?

Why does the list modification work? What is different?

this question bit confusing in terma below

how the list modification related here as we dealing with method and int parammeter?

but as per my understanding of list i am giving answer

list modification work as it is array based implementation and can we access the array using index so at any point of time

can alter the value of list

Modifying parameters:

does it mean numer of params ? if yes then please let me know

as per my understanding and keeping in mind above question

if we modify the parameters of method will get deff output

like above we calculated square root of 9 and we get 3.0 as result

if we call week4(4) then will get 2.0 as result

5. Specifications:

Do we need a return or is a void function acceptable? Could we technically do it either way?

What features do we have to use to accomplish this goal?

return will send the calculated value to caller and void method will nothing return

void week4(int)//it will return nothing possibly can print the output in method it self

double week4(int)//it will return the calculated value and also can print the result or any in between values in method only

also we can use any setter method or any helper method to set the computed value to required code

like void setResult(int rsult)

void printResult(int result)

//Please do let me knwo if u have any concern...

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