Skip to content

Commit

Permalink
palindromic_string_added 2, indentation fixed C/C++ (#2356)
Browse files Browse the repository at this point in the history
  • Loading branch information
MdAkdas authored Mar 23, 2020
1 parent 03077e5 commit 4d56308
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
54 changes: 54 additions & 0 deletions palindromic_string/palindromic_string.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
C Programme to check palindromic string.
A Palindromic String is a sequence of characters which is
the same when read both forward and backward.
*/

#include <stdio.h>
#include <string.h>

// Driver function
int main()
{
char string1[20];
int i, length;
bool flag = false;

printf("Enter a string: ");
scanf("%s", string1);

length = strlen(string1);

for(i = 0; i < length/2; i++)
{
if(string1[i] != string1[length - i - 1])
{
flag = true;
break;
}
}

if (flag)
{
printf("%s is not a palindrome", string1);
}
else
{
printf("%s is a palindrome", string1);
}
return 0;
}

/*
Input:
radar
Output:
radar is a palindrome
Input:
Enter a string: india
Output:
india is not a palindrome
*/
55 changes: 55 additions & 0 deletions palindromic_string/palindromic_string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
C++ Programme to check palindromic string.
A Palindromic String is a sequence of characters which is
the same when read both forward and backward.
*/

#include <iostream>
#include<cstring>
using namespace std;

// Driver function
int main()
{
char string1[20];
int i, length;
bool flag = false;

cout << "Enter a string: ";
cin >> string1;

length = strlen(string1);

for(i = 0; i < length/2; i++)
{
if(string1[i] != string1[length - i - 1])
{
flag = true;
break;
}
}

if (flag)
{
cout << string1 << " is not a palindrome" << endl;
}
else
{
cout << string1 << " is a palindrome" << endl;
}

return 0;
}

/*Input:
radar
Output:
radar is a palindrome
Input:
Enter a string: india
Output:
india is not a palindrome
*/

0 comments on commit 4d56308

Please sign in to comment.