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);
}
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.
To convert an integer array to a string array in C, you can use the sprintf function within a loop to format each integer as a string. First, create a string array with enough space to hold the string representations. Then, iterate through the integer array, using sprintf to convert each integer to a string and store it in the corresponding index of the string array. Here's a simple example: #include <stdio.h> void intArrayToStringArray(int *intArray, char stringArray[][12], int size) { for (int i = 0; i < size; i++) { sprintf(stringArray[i], "%d", intArray[i]); } }
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.
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);
The first integer is unknown. That is because the numbers can keep going on and they never stop. Therefore the answer is unknown.
To arrange numbers in ascending order in QBASIC, you can use a simple sorting algorithm like bubble sort. First, store the numbers in an array. Then, repeatedly compare adjacent elements and swap them if they are in the wrong order until the entire array is sorted. Here's a basic example: DIM numbers(5) AS INTEGER ' (Assume numbers are already populated) FOR i = 0 TO 4 FOR j = 0 TO 4 - i - 1 IF numbers(j) > numbers(j + 1) THEN SWAP numbers(j), numbers(j + 1) END IF NEXT j NEXT i This will sort the array numbers in ascending order.
To find the highest value in an array, start with the first element as the initial maximum. Iterate through each element in the array, comparing it to the current maximum. If an element is greater than the current maximum, update the maximum to this element. After checking all elements, the current maximum will be the highest value in the array.
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.
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 < 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]) >> 1 //here right shifting an integer is same as deviding an integer by 2.
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).
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.
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.