Create isPalindrome() function. Also add in defines for boolean functionality.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
ae9e5b6e5d
commit
13c95790e2
BIN
current
BIN
current
Binary file not shown.
22
src/main.c
22
src/main.c
@ -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…
x
Reference in New Issue
Block a user