Create isPalindrome() function. Also add in defines for boolean functionality.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago committed by GitHub
parent ae9e5b6e5d
commit 13c95790e2
  1. BIN
      current
  2. 22
      src/main.c

Binary file not shown.

@ -1,6 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#define true 1
#define false 0
#define boolean char
/*
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
@ -32,17 +36,29 @@ struct String numberToString(int numb) {
return str;
}
boolean isPalindrome(struct String numb) {
int offset=0;
while (offset<numb.length/2) {
//printf("Compare %c to %c\n",numb.str[offset],numb.str[numb.length-offset-1]);
if (numb.str[offset]!=numb.str[numb.length-offset-1]) {
return false;
}
offset++;
}
return true;
}
int main(int argc,char**argv) {
int numb1=999;
int numb2=999;
int maxPal=0;
printf("%s : %d",numberToString(numb1*numb2).str,numberToString(numb1*numb2).length);
//printf("%s : %d",numberToString(numb1*numb2).str,numberToString(numb1*numb2).length);
/*
if (isPalindrome(numberToString(numb1*numb2))) {
printf("%d is a Palindrome!",numb1*numb2);
}*/
}
return 0;
}
Loading…
Cancel
Save