Skip to content

Instantly share code, notes, and snippets.

@saiprasad1996
Created September 17, 2016 05:35
Show Gist options
  • Save saiprasad1996/9d125cda92d367d12e68949f05324634 to your computer and use it in GitHub Desktop.
Save saiprasad1996/9d125cda92d367d12e68949f05324634 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main() {
int *arr;
int n,i,back;
printf("\nEnter the number of elements for the array");
scanf("%d",&n);
back=n-1;
arr=(int*)malloc(n*sizeof(int));
printf("\nEnter the numbers into the array");
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
//Now checking for palindrome
for(i=0;i<n/2;i++){
if(arr[i]==arr[back]){
// printf("a[i] %d and a[back] %d",arr[i],arr[back]);
//debugging statement
back--;
}else{
//printf("false");
//debugging statement
break;
}
}
printf("\n back value %d and i value %d ",back,i);
if(back==i-1){
printf("\nPalindrome array");
}else{
printf("\nThis array is not a palindrome array");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment