answersLogoWhite

0

Here is an example for type double:

#include

using std::cin;
using std::cout;
using std::endl;

double maxFirst(const double data[], int index);
double maxSecond(const double data[], int index, double maxNumber1);
double sum(double max1, double max2);

int main()
{
const int arraySize = 10;
double myArray[arraySize] ={0.0};

cout << "Enter numbers: " << endl;
for (int i(0); i < arraySize; i++)
{
cout << "Enter " << (i + 1) << " element: ";
cin >> myArray[i];
}

cout << "Your array is: ";
for (int k = 0; k < arraySize; k++)
{
cout << endl << myArray[k];
}

double max1 = maxFirst(myArray, arraySize);
double max2 = maxSecond(myArray, arraySize, max1);

cout << endl << "First biggest number is: " << max1;
cout << endl << "Second biggest number is: " << max2;
cout << endl << "Sum of these two is: " << sum(max1, max2) << endl;

system("PAUSE");
return 0;
}

double maxFirst(const double data[], int index)
{
double maxNumber1 = data[0];
for (int i = 0; i < index; i++)
{
if (maxNumber1 < data[i])
{
maxNumber1 = data[i];
}
}

return maxNumber1;
}
double maxSecond(const double data[], int index, double maxNumber1)
{
double maxNumber2 = data[1];
for (int j = 0; j < index; j++)
{
if (data[j] == maxNumber1)
{
continue;
}
else if (maxNumber2 < data[j])
{
maxNumber2 = data[j];
}
}

return maxNumber2;
}
double sum(double max1, double max2)
{
return (max1 + max2);
}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What is integer array in C programming?

An integer array consists of only integer numbers, for instance, if you have the array of size 5 with integer type date int_array[5] it means that your first element int_array[0] is an integer number like 1, or 15 and so on. The same is true for other elements too; int_array[1](int_array[2], int_array[3], int_array[4]) might be any integer element and so on.


What is the process to find the median of an array of numbers?

To find the median of an array of numbers, first, arrange the numbers in ascending order. If the array has an odd number of elements, the median is the middle number. If the array has an even number of elements, the median is the average of the two middle numbers.


What is integer type array?

An array is a collection of similar data types. An integer array is nothing but a collection of integer data types. Ex: int a[100], int arr[100][100] There are several types. 1D array, 2D array, Multi-Dimensional array. But array is a contiguous allocation. And array size will always be positive. It can be given in the declaration stage or we can specify it dynamically by using malloc function. Ex: int *a; a=(int*)malloc(sizeof(int)*HOW_MANY_NUMBERS_YOU_WANT);


What is the first integer?

The first integer is unknown. That is because the numbers can keep going on and they never stop. Therefore the answer is unknown.


What is array variable?

An array is a variable containing multiple values. Any variable may be used as an array. There is no maximum limit to the size of an array, nor any requirement that member variables be indexed or assigned contiguously. Arrays are zero-based: the first element is indexed with the number 0.


Write c program to find median of two numbers without using division?

First take a array that contain all numbers then sort it. Now take a variable i = 0 and j = n-1 where n = size of array. increment i and decrement j till i &lt; j. Now check that if i == j then a[i] is the median else{ increment j by one and decrement i by one. now median = (a[i] + a[j]) &gt;&gt; 1 //here right shifting an integer is same as deviding an integer by 2.


How do you write a program for counting and displaying occurrence of a number in an array?

Your first step is accepting input, which is done using the scanf() function:scanf("%d", &number);This means that you want scanf() to accept input, convert the input to a number, and store it in the memory at the address of number.Use a for() loop, counting from 0 to 9, and an array of integers to hold the numbers. Then simply scanf("%d", &intarray[counter]);The next step is a little tricky, but not very if you plan it out in advance.Each integer can contain 256, 65,536 or 4,294,967,296 different numbers. Creating an array to hold the count of each of those numbers is a waste of RAM.Instead, you'll want an "associative" array as follows:int numcount[MAXNUM][2];MAXNUM is 10, or the number of integers in the array you're checking. The second dimension, 2, consists of the number and its count.Obviously, you'll want a way to keep track of how many integers you've stored in numcount. An int called numcountnuminitialized to 0 would be the fastest way.Use a for() loop to iterate through the integers. If the integer does not exist in numcount, then set numcount[numcountnum][0] to the integer, set numcount[numcountnum][1] to 1, and increment numcountnum. Otherwise, if the integer exists, increase numcount[the integer index][1].Once the for() loop is finished, display the results. The only thing you have left to figure out is the function that searches the numcount array for an integer, and returns its index (or -1 if it's not found).


What is the most efficient way to find the median of an unsorted array of numbers?

One efficient way to find the median of an unsorted array of numbers is to first sort the array in either ascending or descending order, then determine the middle value as the median.


How do you write a program that accepts 50 integer values and sort them in basic programming?

Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.


How can you separate odd and even numbers from the array of 10 numbers in 8085 microprocessor?

To separate odd and even numbers from an array of 10 numbers in the 8085 microprocessor, you can utilize a loop and the AND instruction. First, load each number from the array into a register and perform a bitwise AND operation with the value 1. If the result is 0, the number is even; if the result is 1, the number is odd. You can then store the odd numbers in one memory location and the even numbers in another, iterating through the entire array until all numbers are processed.


What is array in C languange?

An array is a contiguous block of data in memory. When you declare an array in C you need to give it a type and a name (like a normal variable), plus you need to give it a size. // normal integer variable x int x; // array of 10 integers int x[10]; Remember that the variable x is actually just a pointer, or reference, to a point in memory. This point in memory is the start of the array, so the value at x[0] is the first value in the array, x[1] is the second, and so on. Also remember that C has no bounds checking, so you can, indeed, read any value past the maximum. x[3474] would return an integer value, but it's going to be some part of memory that is not in your array. Attempting to change this value could result in something very bad happening.


What is the minimum unique array sum that can be achieved?

The minimum unique array sum that can be achieved is when all elements in the array are different, resulting in the sum of the array being equal to the sum of the first n natural numbers, which is n(n1)/2.