#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int checkpalindrome(char* a,int n);
int main()
{
char *a;
int i,n;
printf("Enter the size of the string but should be odd => ");
scanf("%d",&n);
a=(char*)calloc(n,sizeof(char));
for(i=0;i<n;i++)
{
if(i==(n-1)/2)
{ printf("Enter X\n");}
scanf("%c",&a[i]);
}
if(checkpalindrome(a,n)){
printf("\nstring is palindrome");
}
else{
printf("\nstring is not a palindrome");
}
return 0;
}
int checkpalindrome(char *a,int n)
{
int i;
for(i=0;i<n;i++)
{
if(a[i]==a[n-i])
continue;
else
return 0;
}
return 1;
}
检查此代码,我没有得到正确的输出这里的字符串应该是a的和b的,而X应该在字符串的中间,我们必须检查该字符串是否是回文。
#include
如果要在单个数组中实现两个堆栈,则需要将初始化数组的大小除以2。然后,必须通过这些基本初始化来区分两个堆栈。