ConsoleApplication3 cpp Defines the entry point for the console applic

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cmath>
#define N 10
int _tmain(int argc, _TCHAR* argv[])
{
double M[N];
int l=1, i, ib=0, max=0, k=1;
printf ("Введите массив:\n");
for (i=0; i<N; i++)
scanf_s("%lf", &M[i]);
for (i=1; i<N; i++)
{
if (M[i]==M[i-1])
k++ ;
else
{
if (k>max)
{
max=k;
ib=i-max;
k=1;
}
else
k=1;
}
}
if (k>max)
{
max=k;
ib=i-max;
k=1;
}
printf ("ib=%d, l=%d\n", ib, l );
printf ("\n");
l=ib+max;
printf ("Полученная последовательность:\n");
for (i=ib; i<l ; i++)
printf ("%lf\n", M[i]);
printf ("\n");
printf ("ib=%d, l=%d\n", ib, l );
return 0;
}