answersLogoWhite

0

To return the largest of a set of variables, store the first variable's value and compare it with all the others, one after the other. Each time a larger value is found, update the stored value. When all variables have been compared, the stored value holds the largest value.

The following demonstrates how to do this for an array of integers:

int largest (int* arr, unsigned size) {

if (!arr size==0) return INT_MIN; // check for invalid arguments

int store = arr[0]; // store first element

for (unsigned i=1; i<size; ++i) if (arr[i]>store) store = arr[i]; // compare with all other values

return store;

}

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

What type of graph is used to compare or determine relationship between variables?

A scatter plot is commonly used to compare or determine the relationship between two variables. It displays individual data points on a Cartesian plane, allowing for visual assessment of correlations, trends, or patterns. Additionally, line graphs can also be employed when illustrating the relationship between variables over time.


What graph is used to compare two variables?

A line graph is used to compare two specific variables.


How does finding slope compare to finding the rate of change between two variables in a linear relationship?

The slope of a line is the same thing as the rate of change between two variables in a linear relationship.


What is the difference between Sound?

... In the english language we compare two things..


How do the test variables and outcome variables in an experiment compare?

Test variables are the factors that are intentionally changed or manipulated by the researcher in an experiment, whereas outcome variables are the factors that are measured and affected by the test variables. Test variables are the independent variables that are controlled by the researcher, while outcome variables are the dependent variables that change in response to the test variables. The relationship between the test variables and outcome variables is explored to determine the effect of the test variables on the outcome variables.


How do the independent and dependent variables in an experiment compare?

the independent variable controls the dependent variables


How can I use the language similarity calculator to compare the linguistic similarities between different languages?

To compare linguistic similarities between different languages using the language similarity calculator, input the two languages you want to compare and analyze the results provided. The calculator will show you the degree of similarity between the languages based on various linguistic factors.


How do the test variables (independent variables) and outcome variables (dependent variables) in an experiment compare?

The test variable (independent variable) controls the outcome variable (dependent variable).


What is the biggest difference between the processes of charging and discharging when you compare them?

The biggest difference between charging and discharging is that charging involves adding energy to a battery or device, while discharging involves releasing energy from a battery or device.


What is the purpose of bar graph?

Graphs help organize information and establish patterns between variables. A graph is a visual way to compare and contrast two or more entities.


What type of graph is used to compare two specific variables?

line graph


What is used as a way to compare values for independent variables in many experiments?

Statistical analysis, such as ANOVA (Analysis of Variance), is commonly used to compare values for independent variables in experiments. ANOVA helps determine if there are statistically significant differences between groups and can reveal which groups differ from each other. This analysis is crucial for drawing conclusions based on the data gathered.