1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ivanzaharov [21]
3 years ago
5

8.19 LAB: Max magnitude Write a function max_magnitude() with two integer input parameters that returns the largest magnitude va

lue. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value. Ex: If the inputs are: 5 7 the function returns: 7 Ex: If the inputs are: -8 -2 the function returns: -8 in c language
Computers and Technology
1 answer:
AysviL [449]3 years ago
7 0

Answer:

#include <iostream>

using namespace std;

int max_magnitude(int firstValue, int secValue)//taking two itnerger inputs

{

if (firstValue > secValue)//using if condition

 return firstValue;

else

 return secValue;

}

int main()

{

int firstVal, secVal, finalVal;

cout << "Enter your first value: " << endl;

cin >> firstVal;

cout << "Enter your second value: " << endl;

cin >> secVal;

finalVal = max_magnitude(firstVal, secVal);//calling function

cout << "The greater value is: " << finalVal << endl;

return 0;//terminating program

}

Explanation:

This exercise is for you to understand how to make and call functions. Functions are a way to basically clean the main code. If you read the main code, you can intuitively tell that the finalVal variable is being assigned a max magnitude of some kind. The program would have run absolutely fine if i simply copy pasted the function inside my main. But imagine, if I had to call this function 1000 times, it would've looked quite ugly.

Secondly, there is a certain way how functions work. Function can, and may not take arguments, depending on what it is supposed to do. for example in this case, the function is taking two arguments, because it needs two compare two values from the main function. Now imagine if I made a function to say, exit the program. I would need any arguments. I would simply call the function and it would say 'return 0' and the program will end.

Thirdly, functions may or may not RETURN a value. I our case if you look closely, our function is called 'int' max_magnitude. The int is signalling what type it will return. This means that when the function completes its processing, it will return to where it was called from and give back the value it ended on.

You might be interested in
In this lab, you will implement a temperature converter in JavaScript. The user may type a temperature in either the Celsius or
jek_recluse [69]

Use the knowledge in computational language in JAVA to write a code that convert the temperature.

<h3>How do I convert Celsius to Fahrenheit in Java?</h3>

So in an easier way we have that the code is:

  • Fahrenheit to celsius:

<em>/* When the input field receives input, convert the value from fahrenheit to celsius */</em>

<em>function temperatureConverter(valNum) {</em>

<em>  valNum = parseFloat(valNum);</em>

<em>  document.getElementById("outputCelsius").innerHTML = (valNum-32) / 1.8;</em>

<em>}</em>

  • Celsius to Fahrenheit:

<em>function cToF(celsius) </em>

<em>{</em>

<em>  var cTemp = celsius;</em>

<em>  var cToFahr = cTemp * 9 / 5 + 32;</em>

<em>  var message = cTemp+'\xB0C is ' + cToFahr + ' \xB0F.';</em>

<em>    console.log(message);</em>

<em>}</em>

<em>function fToC(fahrenheit) </em>

<em>{</em>

<em>  var fTemp = fahrenheit;</em>

<em>  var fToCel = (fTemp - 32) * 5 / 9;</em>

<em>  var message = fTemp+'\xB0F is ' + fToCel + '\xB0C.';</em>

<em>    console.log(message);</em>

<em>} </em>

<em>cToF(60);</em>

<em>fToC(45);</em>

See more about JAVA at brainly.com/question/12975450

5 0
2 years ago
The qwerty keyboard is the most common layout of keys on a keyboard.
vagabundo [1.1K]
The qwerty keyboard is the most common keyboard.
6 0
4 years ago
Read 2 more answers
Which printer management components would you use to view the port a printer uses? (select two. )
masya89 [10]

The printer management components one would use to view the port a printer uses are as follows;

  • Printer properties
  • Printer server properties

<h3>What is Printer management components?</h3>

The print management component provides a single interface where a user can open the print management utility and view all printers and print servers in the enterprise.

The port of a printer is the connector usually on the computer that allow communication with the printer.

Therefore, the printer management components one would use to view the port a printer uses are as follows;

  • Printer properties
  • Printer server properties

learn more on printers port here: brainly.com/question/17157651

#SPJ12

5 0
2 years ago
Fill in the blank with the correct response. Wanting to become a better archer is a what?
Oksi-84 [34.3K]
Is a better archer shooter
5 0
3 years ago
Jim maintains attendance records for his employees for the year. Row B includes the dates of attendance, and column A includes t
EastWind [94]
To lock multiple rows (starting with row 1), select the row below the last row you want frozen, choose the View tab, and then click Freeze Panes. To lock multiple columns, select the column to the right of the last column you want frozen, choose the View tab, and then click Freeze Panes<span>.
</span>
4 0
4 years ago
Read 2 more answers
Other questions:
  • What is the difference between a denial-of-service attack and a distributed denial-of-service attacks? which is potentially more
    10·1 answer
  • Which css property is used to change the text color of an element?
    15·1 answer
  • Think back over the information presented in the lesson about how you can skillfully use the Internet when doing research. Selec
    14·1 answer
  • Which statement is true regarding achievers?
    8·1 answer
  • Computers store temporary Internet files in the Recycle Bin. These files take up space and slow down a computer. Which tool can
    14·1 answer
  • Write a function to output an array of ints on a single line. Funtion Should take an array and an array length and return a void
    9·1 answer
  • A 9-year old male castrated Westie presents on emergency after being rescued from a house fire. On presentation, the dog has a r
    9·1 answer
  • Does kohl's sell homecoming dresses?? And if do you know what the price rage would be !!
    5·1 answer
  • The USGS and National Weather Service have many sensors collecting data about natural events.
    8·2 answers
  • A _______ is a group of elements that you want to style in a particular way.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!