Skip to content

Commit 994cf7d

Browse files
authored
Added palindrome in c
1 parent 2cca71f commit 994cf7d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

C/palindrome.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
int main()
5+
{
6+
char str[] = { "abba" }; //change string to check here
7+
int l = 0;
8+
int h = strlen(str) - 1;
9+
10+
while (h > l) {
11+
if (str[l++] != str[h--]) { //checks if first x char and last x char are the same
12+
printf("%s is not a palindrome\n", str);
13+
return 0;//ends the program here
14+
}
15+
}
16+
17+
printf("%s is a palindrome\n", str);
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)