Created
November 11, 2012 19:30
-
-
Save kiryl/4055993 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | |
int main(int argc, char **argv) | |
{ | |
int arr[20]; | |
int i, r, max; | |
srand(1); | |
for(i = 0; i < ARRAY_SIZE(arr); i++) { | |
arr[i] = rand() % 100; | |
printf("a[%d] = %d ", i, arr[i]); | |
} | |
puts(""); | |
i = 0; | |
r = 0; | |
max = 0; | |
while (i < ARRAY_SIZE(arr) - 1) { | |
printf("i: %d, r: %d, max: %d\n", i, r, max); | |
if (arr[i] < arr[i + 1] && arr[i + 1] > arr[i + 2] ) { | |
r += 2; | |
i += 2; | |
} else { | |
if (r > max) | |
max = r; | |
r = 0; | |
i++; | |
} | |
} | |
if (r > max) | |
max = r; | |
printf("max = %d\n", max); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
include <stdio.h>
include <stdlib.h>
define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
int main(int argc, char **argv)
{
int arr[20];
int i, r, max;
}