Advertisement
Garey

stela_zad_ktrl

Nov 24th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int input_array(double A[], int n) {
  6.     for(int i = 0; i < n; i++) {
  7.         cout << "Enter element #" << i << ": ";
  8.         cin >> A[i];
  9.     }
  10.  
  11.     return *A;
  12. }
  13.  
  14. void output_array(double A[], int n) {
  15.     for(int i = 0; i < n; i++)
  16.         cout << A[i] << endl;
  17. }
  18.  
  19. void min(double A[], int n) {
  20.     // Min gets value of 1st element in the array
  21.     int min = A[0];
  22.  
  23.     for(int i = 0; i < n; i++)
  24.         if(min > A[i] && A[i] < 0)
  25.             min = A[i];
  26.  
  27.     cout << "Min number is " << min << " and its' index is" << i;
  28. }
  29.  
  30. int main() {
  31.     double A[25];
  32.     int n;
  33.  
  34.     cout << "Enter array size: ";
  35.     cin >> n;
  36.  
  37.     // Check if n is smaller than 0 or bigger than 25
  38.     if(n < 0 || n > 25)
  39.         return 0;
  40.  
  41.     // Inputting array
  42.     input_array(A, n);
  43.  
  44.     //Minimum negative number
  45.     min(A, n);
  46.  
  47.     // Output array
  48.     cout << "\n\nArray Output:\n";
  49.     output_array(A, n);
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement