SHARE
TWEET

Untitled

a guest Oct 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Example program
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int find_maximum(int a[], int n)
  6. {
  7.     //declare c, max and index as integer types
  8.     int c, max;
  9.     int index = 0;
  10.  
  11.         //assign max as the first element in array a
  12.     max = a[0];
  13.  
  14.  
  15.     for (c = 1; c < n; c++)
  16.     {
  17.         if (a[c] > max)
  18.         {
  19.             // assign index to c
  20.             c = index;
  21.                 // assign index to the cth element in array a
  22.                 max = a[c];
  23.         }
  24.     }
  25.    
  26.     return index;
  27. }
  28.  
  29. int main()
  30. {
  31.     //declare variables
  32.     int size, location, maximum;
  33.  
  34.     //print "Input number of elements in array" followed by a line feed
  35.    
  36.  
  37.         //Input variable "size" from input console
  38.     cin >> size;
  39.  
  40.     cout << "Enter " << size << " integers" << endl;
  41.  
  42. int array[size];
  43.     //use c as a counter within a loop until size to enter all elements in the array
  44.     for (int i = 1; i <= size; i++)
  45.     {
  46.         cin >> array[i-1];
  47.        
  48.     }
  49.     cout << "ok";
  50.  
  51.         location = find_maximum(array, size);
  52.     //assign maximum to the array location returned by the find_maximum function
  53.     maximum = array[location];
  54.  
  55.         cout << "Maximum element location = " << (location ) << " and value = " << maximum << endl;
  56.     return 0;
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top