In this post, we will talk about the palindrome program in c And we will know. What is a palindrome? And how to make the Palindrome program.
To understand this program, you must have this knowledge:
what is Palindrome?
In the most simple terms, a palindrome is a word, phrase, or number which reads the same backwards as it does when being read forwards. it does not matter if there are punctuation marks within the palindrome
these do not count and if they are present, the sequence or word will still fall under the category of the palindrome.
the word palindrome originally comes from the greek language and is made up of two words, the first being palin which translates to mean again and the second being dromos which translates to mean direction or way.
the palindrome, when read backwards will have the same pattern, layout, appearance, sound, and meaning. For the use of the palindrome in the English language, we can thank a man named Ben jonson who introduced the idea way back in the 17th century.
Palindrome example:
stats, madam, wow, level, refer 191 225522 222 9955599
source code: palindrome program in c
Output Screen
Enter your String: computer Not palindrome:retupmoc Enter your String: level palindrome:level
Program Logic
First, we will take input in an array named Ustring
.
Then we will copy the string in the Nstring
array with the help of strcpy
function.
Will create another strcpy
function. Nstring
and reverse
function will pass in it. We will pass Ustring
in reverse function.
From here the cursor will go to the definition of the reverse function. In the argument bracket of the reverse function, we will create a pointer named code1
.
Inside the reverse we will make i
and l
. And we will create an ancientcode
variable of type char
.
Then we will put a loop
. The length of string will be obtained with the help of l
and code1
.
Put another loop And in that i
will run till length/2
.
Then inside the loop we will do swapping with the help of pointer. After that function will return value of code1
.
now cursor will move on previous position where reverse function call was made.
The reverse function that will return the value. The same will be copied to Rstring
.
We will then call the Oracle
function. And will pass Nstring
and Rstring
in it. The cursor will go to the oracle
function. Then the code of the Oracle function will be executed.
Inside the function, we will create an orange
variable. we will call the strcmp
function then will pass Nstring
, Rstring
. strcmp
will return an integer value that will be assigned to a variable named Orange
.
Then we will apply the if-else
condition. And will check. if orange
equal to 0
So the return is a palindrome
variable. Otherwise, return no_palindrome variable. Then the Oracle function will return value. that value will be assigned to s1.
Here we will once again apply the if-else
condition. if s1
equal to 1
. So the string is a palindrome. Otherwise, there is no palindrome.
Recommended Post
- #define in c
- Number searching program through enum in c
- c program for multiplication of two matrices
- c program fibonacci series using recursion
- coprime number program
- c program swap two numbers using pointers
😊
Now next you are, write your code in the comment below.😊
0 Comments:
Post a Comment
Please do not enter any spam link in the comment box.