Kiểm tra chuổi đối xứng

March 07, 2023
Viết chương trình nhập vào từ bàn phím một chuỗi ký tự và kiểm tra xem chuổi đó có đối xứng không.
Ví dụ: Chuỗi ABCDEDCBA là chuỗi đối xứng.




Bài Giải


/*
Name: Test chuoi doi xung
Copyright: None
Author: Tran Anh
Description: https://gimi.vn
*/
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<malloc.h>
main()
{
 char *s;
 s=(char*)calloc(255,sizeof(char));

 printf("\t- Nhap vao chuoi: ");
 gets(s);

 int test=1,i=0,n=strlen(s);
 for(i=0;i<=(n/2);i++)
  if (s[i]!=s[n-i-1])
  {
   test=0;
   break;
   }

 if (test)
  printf("\t=> Chuoi doi xung");
 else
  printf("\t=> Chuoi khong doi xung");

 getch();

return 0;
    

}