1 #include "stdafx.h"
2 #include "iostream"
3 4 using namespace std;
5 6 int isechol (
const char* str)
7 {
8 int length = strlen(str); 9 for (int i=0; i<length/2; i++)10 {11 // 0代表不是,1代表是
12 if (str[i] != str[length-i-1])
13 {
14 return 0;
15 }
16 }
17 return 1;
18 }
19 20 int main(
int argc,
char* argv[])
21 {
22 printf("Hello World!\n");
23 char buf[10] = "abcddcba";
24 if (isechol(buf))
25 cout << buf << " is echol" << endl;
26 else27 cout << buf << " is not echol" << endl;
28 return 0;
29 }
输出:
Hello World!
abcddcba is echol
Press any key to continue