Advertisement
Domerk

С2_3

Mar 8th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. //*Программа, ищущая номер первого из трёх последовательных элементов в целочисленном массиве из 30 элементов, сумма которых максимальна.
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <ctime>
  6. using namespace std;
  7. int main ()
  8. {
  9.     unsigned short m[30];
  10.     srand (time(NULL));
  11.     int i=0, summ_max=0, imax=0;
  12.  
  13.     while (i<30)
  14.     {
  15.         m[i]=rand();
  16.         i++;
  17.     }
  18.  
  19.     i=0;
  20.     while (i<28)
  21.     {
  22.         if ((m[i]+m[i+1]+m[i+2]) > summ_max)
  23.         {
  24.             summ_max=m[i]+m[i+1]+m[i+2];
  25.             imax=i;
  26.             i++;
  27.         }
  28.     }
  29.  
  30.     cout<<"summ max ="<<summ_max<<endl<<"№"<<imax;
  31.     cin.sync();
  32.     cin.clear();
  33.     cin.get();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement