Results 1 to 4 of 4

Thread: C# program for palindrome

  1. #1
    Harvey Lavan is offline Member
    Join Date
    Sep 2009
    Posts
    57
    Rep Power
    3

    Default C# program for palindrome

    Hi. I am learning C# programming language. I want to write palindrome program. I tried different code but none of them worked out. Please help me to get rid of this problem. Thanks in Advance.

  2. #2
    Join Date
    Sep 2009
    Posts
    68
    Rep Power
    3

    Default

    Try out this code, when you run this program you get the word is palindrome or not:
    Code:
    Palindrome using C#.net
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    string str=string .Empty ;
    
    Console.WriteLine("Enter a String");
    
    string s = Console.ReadLine();
    
    int i = s.Length;
    //we can get the Length of string by using Length Property
    
    for (int j=i -1; j >= 0; j--)
    {
    str = str + s[j ];
    }
    if (str == s)
    {
    
    Console.WriteLine(s + " is palindrome");
    
    }
    else
    {
    Console.WriteLine(s + " is not a palindeome");
    }
    
    Console.WriteLine(str);
    
    Console.Read();
    
    }
    }
    }

  3. #3
    Join Date
    Sep 2009
    Posts
    59
    Rep Power
    3

    Default

    Refer following program to check given string is palindrome or not:
    Code:
    bool CheckPalindrome (string CheckString)
    {
         if (CheckString == null || CheckString.Length == 0) 
         {
            return false;
         }
         for (int i = 0; i < CheckString.Length / 2; i++)
         {
             if (CheckString[i] != CheckString[CheckString.Length - 1 - i])
             {
                return false;
             }
         }
         return true;
    }

  4. #4
    prabhulingayya is offline Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Refer following program to check given string is palindrome or not: Code:

    private static void CheckPalindrome()
    {
    string s1 = string.Empty;
    Console.WriteLine("Please enter a string: ");
    s1 = Console.ReadLine();
    int length = s1.Length;
    bool flag=false;
    int j = length - 1;
    for (int i = 0; i < (length/2); i++)
    {
    if (s1[i] != s1[j--])
    {
    flag=true;
    break;
    }
    Console.WriteLine("{0}",j);

    }
    if (flag)
    Console.WriteLine("String is not a Palindrome");
    else
    Console.WriteLine("String is Palindrome");
    }

Similar Threads

  1. C code for palindrome
    By Keith Fletcher in forum Programming
    Replies: 2
    Last Post: 07-30-2010, 11:04 PM
  2. Palindrome in java
    By BarnesHarris in forum Programming
    Replies: 1
    Last Post: 06-11-2010, 02:27 PM
  3. Replies: 1
    Last Post: 05-03-2010, 01:37 PM
  4. Write program on palindrome in java
    By MoralesMyers in forum Programming
    Replies: 2
    Last Post: 01-14-2010, 06:24 PM
  5. C# program for palindrome
    By JacksonPerez in forum Programming
    Replies: 0
    Last Post: 01-13-2010, 06:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48