Skip to content

Commit

Permalink
Merge pull request #30 from diego95root/master
Browse files Browse the repository at this point in the history
Add Diego Bernal
  • Loading branch information
TANIYA GUPTA authored Oct 14, 2018
2 parents 21db382 + 7f4bf86 commit 6fbc6ae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added ASSIGNMENTS/Largest Palindrome
Binary file not shown.
29 changes: 29 additions & 0 deletions SOLUTIONS/Largest Palindrome.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
int cases, len, pal = 0, num, i;
char n[10];
scanf("%i", &cases);
for (;cases!=0;cases--){
scanf("%9s", n);
for (len=0;n[len]!='\0';len++);
num = atoi(n); // to decrease number
while (pal == 0){ // while no palindrome keep searching
sprintf(n, "%i", (num-1));
for (i = 0; i<len/2;i++){ // check if number is palindrome, else break and other number
if (n[len-1-i] == n[i]){ pal = 1 }
else {
pal = 0;
break;
}
}
num = atoi(n); // array to int to be able to decrease num
}
if (pal == 1){
printf("%d\n", num);
cases = len = pal = num = 0; // reinitialize everything so that results don't influence each other
}
}
}

0 comments on commit 6fbc6ae

Please sign in to comment.