Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- using namespace std;
- int find_maximum(int a[], int n)
- {
- //declare c, max and index as integer types
- int c, max;
- int index = 0;
- //assign max as the first element in array a
- max = a[0];
- for (c = 1; c < n; c++)
- {
- if (a[c] > max)
- {
- // assign index to c
- c = index;
- // assign index to the cth element in array a
- max = a[c];
- }
- }
- return index;
- }
- int main()
- {
- //declare variables
- int size, location, maximum;
- //print "Input number of elements in array" followed by a line feed
- //Input variable "size" from input console
- cin >> size;
- cout << "Enter " << size << " integers" << endl;
- int array[size];
- //use c as a counter within a loop until size to enter all elements in the array
- for (int i = 1; i <= size; i++)
- {
- cin >> array[i-1];
- }
- cout << "ok";
- location = find_maximum(array, size);
- //assign maximum to the array location returned by the find_maximum function
- maximum = array[location];
- cout << "Maximum element location = " << (location ) << " and value = " << maximum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement