• +91 9723535972
  • info@interviewmaterial.com

CSharp Interview Questions and Answers

Question - Write a program in C# Sharp to find if a given string is palindrome or not?

Answer -

internal static void chkPalindrome(string str) 
   bool flag = false; 
   for (int i = 0, j = str.Length - 1; i < str.Length / 2; i++, j--) 
   { 
       if (str[i] != str[j]) 
       { 
           flag = false; 
           break; 
       } 
       else 
           flag = true; 
   } 
   if (flag) 
   { 
       Console.WriteLine("Palindrome"); 
   } 
   else 
       Console.WriteLine("Not Palindrome");
Output: 

Input: Key Output: Not Palindrome
Input: step on no pets Output: Palindrome 

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners