int main(int argc, char **argv) {
    // Pre: User passes as a parameter the number of digits to find the product from
    // better checking would be required
    int n = atoi(argv[1]);

    // Create biggest number with n digits and assign to n1 and n2
    char *s_biggest_with_n = malloc(n);
    int i, j;
    for(i=0; i<n; i++) s_biggest_with_n[i] = '9';
    int biggest_with_n;
    sscanf(s_biggest_with_n, "%d", &biggest_with_n);
    free(s_biggest_with_n);

    //Keep decreasing the numbers until the bigger palindrom id found
    int max = 0;
    for (i=biggest_with_n; num_digits(i) == n; i--) {
        for (j=biggest_with_n; num_digits(j) == n; j--) {
            int pal = i*j;
            if (is_palindrom(pal) && pal > max) {
                max = pal;
            }
        }
    }
    printf("%d\n", max);
    return 0;
}
Exemplo n.º 2
0
int palset(char* the_string, int length){
  int end_char = 0;
  int start_char = 0;
  int pal = 0;
  end_char = length - 1;
  pal = is_palindrom(the_string, start_char, end_char);
  return pal;
}
Exemplo n.º 3
0
int is_palindrom(char* the_string, int start_char, int end_char){
  int is_pal = 0;
  if(start_char >= end_char)
    is_pal = 1;
  else if(the_string[start_char] == the_string[end_char]){
    end_char--;
    start_char++;
    is_pal = is_palindrom(the_string, start_char, end_char);
  }
  return is_pal;
}
Exemplo n.º 4
0
void problem4()
{
    int maxx = 0;
    for (int i = 999; i > 99; --i) {
        for (int j = 999; j > 99; --j) {
            int mul = i*j;
            if (mul > maxx && is_palindrom(mul))
                maxx = mul;
        }
    }

    std::cout << maxx;
}
Exemplo n.º 5
0
int main()
{
    LinkedNode *list1 = get_list(100, 500, UNIQUE_NON_SORTED);
    LinkedNode *list2 = get_list(100, 500, UNIQUE_NON_SORTED);

    if (!(list1 && list2))
	return 0;

    printf("list1:\n");
    print_list(list1);

    LinkedNode *head1 = list1;
    LinkedNode *head2 = list2;
    while (head1->next){
	head2->value = head1->value;
	head1 = head1->next;
	head2 = head2->next;
    }
    //head2->value = 1234;
    head2->value = head1->value;
    head2 = NULL;

    LinkedNode *node = (LinkedNode*)malloc(sizeof(LinkedNode));
    if (node == NULL)
	return 0;
    node->visit = 0;
    node->value = 7777;
    node->next = NULL;

    //make ODD list
    head1->next = node;
    head1 = head1->next;

    while (list2){
	LinkedNode *temp = list2;
	list2 = list2->next;
	temp->next = head2;
	head2 = temp;
    }
    head1->next = head2;
    printf("palindrom list1:\n");
    print_list(list1);

    if (is_palindrom(list1) == true)
	printf("is palindrom!\n");
    else
	printf("is not palindrom!\n");

    return 0;

}
Exemplo n.º 6
0
int main() {

   char word[] = "xamax";
   if (is_palindrom(word)) printf ("It's a palindrome\n");
}