Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include      <stdio.h>
  2. #include     <stdlib.h>
  3. #include     <iostream>
  4. using    namespace std;
  5.  
  6.  
  7. ///////////////////////////////////////////////////
  8. int main()                                       //
  9. {
  10.    
  11.     setlocale(LC_ALL, "rus");
  12.    
  13.     int                   *a,
  14.                            n,
  15.                            i,
  16.                  min = 99999,
  17.                      max = 0,
  18.                       minnum,
  19.                       maxnum;
  20.                  
  21.    
  22.     cout << "Введите длину последовательности: ";    cin >> n;
  23.    
  24.     a = (int*)malloc(n * 4);
  25.    
  26.     cout << "Введите последовательность: " << endl;
  27.    
  28.     for(i=0; i < n; i++) cin >> a[i];                                                           //scanf("%d", &a[i]);
  29.    
  30.     for(i=0; i<n; i++ )
  31.     {
  32.        
  33.         if(a[i] < min)
  34.         {
  35.            min = a[i];
  36.            minnum = i;        
  37.         }
  38.     }
  39.    
  40.     for(i=0; i<n; i++)
  41.     {
  42.         if(a[i] > max)
  43.         {
  44.            max = a[i];
  45.            maxnum = i;
  46.         }
  47.     }
  48.     cout << "номер минимального элемента: " << minnum+1
  49.  << endl << "номер максимального элемента: " << maxnum+1 << endl;
  50.      
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement