summaryrefslogtreecommitdiffstats
path: root/mat/euler/4/prog.c
blob: 151dea9f257a47e4adb5ce9fa467d99092deb64d (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char ** argv) {
	if (argc != 1+2) {
		fprintf(stderr, "uporaba: %s <min> <max>\nprimer: %s 100 999\n", argv[0], argv[0]);
		return 1;
	}
	size_t i, k;
	unsigned long long int d = 0;
	unsigned long long int j[2];
	unsigned long long int min = atoi(argv[1]);
	unsigned long long int max = atoi(argv[2]);
	unsigned long long int step = 1;
	char s[256] = "";
	for (j[0] = min; j[0] <= max; j[0]++)
		for (j[1] = min; j[1] <= max; j[1]++) {
			sprintf(s, "%lld", j[0]*j[1]);
			i = strlen(s);
			for (k = 0; k < i; k++)
				if (s[k] != s[(i-1)-k])
					break;
				else if (k >= i-1 && d < j[0]*j[1])
					d = j[0]*j[1];
		}
	fprintf(stdout, "konec. našel največji palindrom %lld.\n", d);
	return 0;
}