Palindrome check for an array

Program to check if the entered array is a palindrome or not..

#include<stdio.h>
#include<conio.h>
main()
{
int a[30],b[30],i,n,swap,temp=0;
clrscr();
printf("Enter n\n" );
scanf("%d",&n);
printf("Enter the array elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
b[n-i-1]=a[i];
}
for(i=0;i<=(n/2);i++)
{
swap=a[i];
a[i]=a[n-i-1];
a[n-i-1]=swap;
}
for(i=0;i<n;i++)
{
if(a[i]==b[i])
temp=1;
}
printf("Reversed array is \n");
for(i=0;i<n;i++)
printf("%d\n",b[i]);
if(temp)
printf("The entered array is a palindrome");
else
printf("The entered array is not a palindrome");
getch();
return 0;
}
Category:

0 comments: