Skip to content

Instantly share code, notes, and snippets.

@resure
Created March 20, 2011 19:48
Show Gist options
  • Save resure/878616 to your computer and use it in GitHub Desktop.
Save resure/878616 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <locale.h>
#include <string.h>
#include <stdlib.h>
int main() {
int i=-1, nums[100], pr = 0, n = 0, max[3];
char str[100][100];
setlocale(0, "russian");
max[0] = max[1] = max[2] = 0;
printf("Введите числа:\n");
do {
i++;
scanf("%s", str[i]);
nums[i] = atoi(str[i]);
} while (str[i][ strlen(str[i]) - 1 ] != '0');
n = i + 1;
printf("\n\n");
for (i = 0; i < n-1; i++) {
pr = nums[i] * nums[i+1];
if (pr > nums[max[2]])
if (pr > nums[max[1]]) {
if (pr > nums[max[0]]) {
max[2] = max[1];
max[1] = max[0];
max[0] = i;
} else {
max[2] = max[1];
max[1] = i;
}
} else {
max[2] = i;
}
}
for (i = 0; i < 3; i++)
printf("#%d. Индекс: %d. Значение: %d. Адрес: %p\n", i + 1, max[i] + 1, nums[max[i]], &(str[max[i]]));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment