Computers and Technology
20.05.2020 07:40
168
458
9
Solved by an expert

Write the definition of a function absoluteValue, that receives an integer parameter

Write the definition of a function absoluteValue, that receives an integer parameter and returns the absolute value of the parameter's value. (You should write the logic for absolute value yourself... do not use the abs function of the C library.) So, if the parameter's value is 7 or 803 or 141 the function returns 7, 803 or 141 respectively. But if the parameter's value is -22 or -57, the function returns 22 or 57 (same magnitude but a positive instead of a negative). And if the parameter's value is 0, the function returns 0.
Show Answers
emilyy6425
emilyy6425
4,4(40 marks)

int absoluteValue(int number) {

   if (number < 0)

       number = number * (-1);

   else if (number > 0)

       number = number;

   else

       number = 0;

       

   return number;

}

Explanation:

Create a function called absoluteValue that takes an integer parameter, number

Check if the number is smaller than 0. If it is, multiply the number with -1

Check if the number is greater than 0. If it is, assign it to itself

Check if the number is 0. If it is, assign it to 0

Return the number

lilpeepxliltracy
lilpeepxliltracy
4,4(3 marks)

Film genre is the category or style a film falls in to.

Popular Questions about the subject: Computers and Technology

Write an if statement that prints the message The number is not valid if the...
Computers and Technology
22.03.2021 05:12
Write the code to call a function whose name is send_number. There is one argument...
Computers and Technology
15.04.2022 20:52
A technician is troubleshooting a PC with multiple volumes. To verify which...
Computers and Technology
09.07.2022 05:21
For each of the following languages, specify if the language is regular or...
Computers and Technology
20.10.2020 13:38
A writing team wants to present the six-month sales figures for its company...
Computers and Technology
22.09.2022 05:20
refers to the combination of hardware, software, and services that people use...
Computers and Technology
18.02.2020 06:19
Suppose a MATV/SMATV (Satellite Master Antenna Television) firm has to start...
Computers and Technology
10.06.2021 01:30
is a systems development technique that produces a graphical representation...
Computers and Technology
07.08.2022 13:28
Develetech has recently been plagued with malware because of users bringing...
Computers and Technology
06.01.2022 07:33
Stacy’s fault-tolerant system only crashes if there are k = 10 consecutive...
Computers and Technology
09.05.2022 19:28

New questions by subject

What makes producers so unique compared to other organisms in any ecosystem?...
Biology
22.09.2022 05:03
Solve the triangle, find m∠A and m∠C. Round angles to the nearest degree. m∠A=...
Mathematics
22.01.2023 00:09
The sensibility of Romanticism is feeling. True False...
Arts
14.05.2023 04:51
Triangle efg is shown in the graph what will be the coordinates of g NEED HELP...
Mathematics
27.08.2021 00:14
Anwer this question 10 times 2...
History
21.03.2023 02:48
PLS HELP ASAP BEST ANSWER WILL BE MARKED BRAINLIEST!!! What changed for Native...
History
14.07.2020 02:58
Marissa substracted a negative number from a positive number. Her result was...
Mathematics
25.06.2021 02:20
Based on society in the late 1800s, how effective were Reconstruction Era reforms...
History
17.07.2020 05:42
#
#
#
#
# #

We expand our knowledge with many expert answers