String palindrome program

String palindrome in c

#include<stdio.h>
#include<conio.h>
#include<string.h>
void Check(char arr[]);
void main()
{
	char input[100];
	printf("Enter your string \n");
	gets(input);
	Check(input);
	getch();
}
void Check(char arr[])
{
	int i=0;
	int len=strlen(arr)-1;
	int count=0;
	while(len>i)
	{
		if(arr[i++] != arr[len--])
		{
			count++;
		}
	}
	if(count>0)
	{
		printf("This string is not palindrome");
	}
	else
	{
		printf("This string is palindrome");
	}
}

Output

Enter your string
abba
This string is palindrome

String palindrome in c++

#include<iostream>
#include<conio.h>
#include<string>
#include<string.h>
using namespace std;
class Example
{
public:
void Check(char arr[])
{
	int i=0,count=0;
	int len=strlen(arr)-1;
	while(len>i)
	{
		if(arr[i++]==arr[len--])
		{
			count++;
		}
	}
	if(count>0)
		cout<<"This string is palindrome";
	else
		cout<<"This string is not palindrome";
}
};
void main()
{
char input[100];
cout<<"Enter your string \n";
cin>>input;
Example ex;
ex.Check(input);
getch();
}

Output

Enter your string
abbba
This string is palindrome

String palindrome in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringPalindrome
{
class Program
{
    string _input;

public string Input
{
    get { return _input; }
    set { _input = value; }
}
public void Check()
{
    int i = 0, count = 0;
    int len = this.Input.Length-1;
    while (len > i)
    {
    if (this.Input[i++] == this.Input[len--])
        count++;
    }
    if (count > 0)
    Console.Write("This string is not palindrome");
    else
    Console.Write("This string is palindrome");
}
static void Main(string[] args)
{
    string input;
    Console.WriteLine("Enter your string");
    input = Console.ReadLine();
    Program p1 = new Program();
    p1.Input = input;
    p1.Check();
    Console.ReadLine();
}
}
}

Output

Enter your string
bgggb
This string is palindrome

String palindrome in java

import java.util.*;
class AB
{
	public void Check(String input)
	{
	    int i = 0, count = 0;
	    int len = input.length()-1;
	    char[] arr=input.toCharArray();
	    
	    while (len > i)
	    {
	    if (arr[i++] != arr[len--])
	      count++;
	    }
	    if (count > 0)
	    System.out.println("This string is not palindrome");
	    else
	    System.out.println("This string is palindrome");
	}
	
}
class examples
{
public static void main(String[] args)
	{
     String input;
     Scanner obj= new Scanner(System.in);
     System.out.println("Enter your string");
     input=obj.next();
     
     AB ab=new AB();
     ab.Check(input);
	}
}

Output

Enter your string
mkkkkm
This string is palindrome

Write a comment


Name Email Message