Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
palindrome
//g++ 7.4.0 //write a function that tests whether an array is palindrome or not; an array is palindrome when its reverse looks similar to the original one; //the function takes an integer array and an integer as parameters and returns an integer; //this code is created by Rezaul Hoque on June 19,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; int n=7; int isPalindrome(int [], int ); int isPalindrome(int a[], int n){ int count=0; int i; //in palindrome, elements of the original array and those of reverse array are same(i.e. "121","ADA" etc); so a[0] is same as a[n-1] and a[n-1] is same as a[0];using this idea, frequency of match is used to conclude whether an array is palindrome or not; starting from i=0,1,2,...n-1 , there will be exactly n(size of array) matches in case of a palindrome; any short of n matches leads to conclude that the array does not form a palindrome ; //here count is used to trace the match for (i=0;i<n;i++) if (a[i]==a[n-i-1]) count++; return count; } int main() { int a[n]= {11,12,13,14,13,12,11}; int result; result=isPalindrome(a, n);//number of total count or match is assigned to result if(result==n)//if the total match is equal to the size of array n, then it is a palindrome {cout<<"\nThe array forms a palindrome.";} else {cout<<"\nThe array does not form a palindrome.";} return 0; }
run
|
edit
|
history
|
help
0
pi with cmath
Test
Test Euler Graph
Test 5(2020)
myfirst.cpp
2021(M2)Simulare:S3:1
google
semiprog.cpp
Hello World
BridgeEdge