Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <time.h>
- #include <stdlib.h>
- int n;
- void monitor(int *p, int n)
- {
- int a = 0;
- int summ = 0,
- nF = 0,
- nCount = 3;
- cout << "количество элементов = "<<n << endl;
- for(int i = 0; i < n; i++)
- {
- cout << p[i] << ", ";
- if(nF == 1)
- {
- if(nCount > 0) summ += p[i];
- nCount--;
- }
- if(p[i] == 7)
- {
- a = i;
- nF = 1;
- }
- }
- // for(int i = a; i < a + 3; i++)
- // {
- // summ += p[i + 1];
- // }
- // if((n - a) < 3) summ
- // if((n - a) < 2)
- // if((n - a) < 1)
- cout << "\n индекс элемента с числом 7 = "<< a << endl;
- cout << "\n сумм после 7 = "<< summ << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- srand(time(0));
- n = rand()%21 + 10;
- int* p = (int*)malloc(sizeof(int) * n);
- cout << p << endl;
- int nFlag = 0;
- L0_1:
- for(int j = 0; j < n; j++)
- {
- p[j] = rand()%101;
- if(p[j] == 7) nFlag = 1;
- }
- if(nFlag == 0) goto L0_1;
- monitor(p, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment