-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevstr.c
More file actions
42 lines (38 loc) · 785 Bytes
/
revstr.c
File metadata and controls
42 lines (38 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() {
char str[50];
scanf("%[^\n]s", str);
int len = strlen(str);
char str2[len];
for (int i=0; i<len; i++) {
str2[i] = str[len-i-1];
}
str2[len] = '\0';
printf("%s", str2);
return 0;
}
//palindrome checker
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() {
char str[50];
scanf("%[^\n]s", str);
int len = strlen(str);
char str2[len];
for (int i=0; i<len; i++) {
str2[i] = str[len-i-1];
}
int cnt = 1;
for (int i=0; i<len; i++) {
if (str2[i] != str[i]) {
cnt = 0;
}
}
if (cnt == 0) {
printf("not a palindrome");
} else printf("is a palindrome");
return 0;
}