Skip to content

Commit

Permalink
(jainaman224#1646) Implementation of palindrome in C & C++ GSSoC'20 (j…
Browse files Browse the repository at this point in the history
…ainaman224#1825)

Added code for implementation of palindrome in C/C++
  • Loading branch information
MastersAbh authored and Amitsharma45 committed May 31, 2020
1 parent 6fae0ca commit 4c8d7fa
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Palindrome/palindrome_no.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
This program checks whether the enterd number is palindrome or not and generates output according to input provided.
*/

#include<stdio.h>
int main()
{
int n,rem,temp,rev = 0;
printf("\nEnter a number: ");
scanf("%d",&n);
temp = n;
while(temp != 0)
{
rem = temp % 10;
temp = temp / 10;
rev = (rev * 10) + rem;
}
if(rev != n)
{
printf("\nEntered number is not palindrome.\n");
}
else
{
printf("\nEntered number is palindrome.\n");
}
return 0;
}



/*
INPUT:
n=12456
OUTPUT:
Entered no. is not palindrome.
INPUT:
n=12821
OUTPUT:
Entered no. is palindrome.
*/
43 changes: 43 additions & 0 deletions Palindrome/palindrome_no.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
This program checks whether the enterd number is palindrome or not and generates output according to input provided.
*/


#include<iostream>
using namespace std;
int main()
{
int n,rem,rev = 0;
cout << "Enter a number: ";
cin >> n;
int temp = n;
while(temp != 0)
{
rem = temp % 10;
temp = temp / 10;
rev = (rev * 10) + rem;
}
if(rev != n)
{
cout << "Entered number is not palindrome." << endl;
}
else
{
cout << "Entered number is palindrome." << endl;
}
return 0;
}



/*
INPUT:
n=12456
OUTPUT:
Entered no. is not palindrome.
INPUT:
n=12821
OUTPUT:
Entered no. is palindrome.
*/
51 changes: 51 additions & 0 deletions Palindrome/palindrome_string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
This program checks whether the enterd string is palindrome or not and generates output according to input provided.
*/

#include<iostream>
#include<string.h> // to use swap()
using namespace std;

void string_palindrome(string s)
{
string reverse = s;
int n = s.length();
for(int i=0;i<n/2;i++)
{
swap(reverse[i], reverse[n-i-1]);
}
if(reverse == s)
{
cout << s <<" is Plindrome." << endl;
}
else
{
cout << s << " is not Palindrome." << endl;
}
}
int main()
{
string str;
cout << "Enter a string: ";
cin >> str;
string_palindrome(str);
return 0;
}



/*
INPUT:
Enter a string: abhnch
OUTPUT:
abhnch is not Palindrome.
_______________________________________
INPUT:
Enter a string: adbcbda
OUTPUT:
adbcbda is Palindrome.
*/

0 comments on commit 4c8d7fa

Please sign in to comment.