#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void input(double arr[], const int arr_size);
double max(double arr[], const int arr_size);
int main()
{
const int arr_size = 5;
double arr[arr_size] = {0.0};
input(arr, arr_size);
cout << "Highest number is: " << max(arr, arr_size) << endl;
system("PAUSE");
return 0;
}
void input(double arr[], const int arr_size)
{
cout << "Enter " << arr_size << " elements to find the highest:" << endl;
for (int i = 0; i < arr_size; i++)
{
cout << (i + 1) << " element is: ";
cin >> arr[i];
}
}
double max(double arr[], const int arr_size)
{
double highest_num = arr[0];
for (int i = 0; i < arr_size; i++)
{
if (highest_num < arr[i])
{
highest_num = arr[i];
}
}
return highest_num;
}
Chat with our AI personalities
find even number in array
i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?
If you have the series stored in an array, you loop through the array and print each array element in turn. Another possibility is to print out the numbers in the series as you generate them. In that case, you may not need to store anything (depending on the series, of course).
Yes but why.
Well the most prolific answer to this query would be the use of pointers.Use a pointer and allocate it to the array of interest and start printing.