-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
palindromic_string_added 2, indentation fixed C/C++ (#2356)
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |