Tech Point Fundamentals

Thursday, December 23, 2021

C# Program to Check for Palindrome

C# Program to Check for Palindrome

coding-interview-question-csharp

Most of the IT companies check the coding skills and problem-solving skills as well along with the theoretical interview questions. Sometimes you are free to write the pseudo code and sometimes you are asked to write the complete program either on any paper or any editor. 


This question is asked in the coding interview to write the program. Here you can find the program as well as a live running program so that you can test the program immediately.


Watch our videos here





Question: 


How can you check whether the given string is a palindrome or not? Write a program for checking palindrome.




C# Program To Find the Palindrome


       
 

// Author 	: Tech Point Fundamentals
// Website 	: www.techpointfunda.com
// Channel	: https://www.youtube.com/c/TechPointFundamentals
// Demo		: Checking for Palindrome

using System;

public class Program
{
 public static void Main()
 {
   string inputString = "NAYAN";		
   string inputString2 = "12321";
   string inputString3 = "TechPointTech";
   
   Console.WriteLine(String.Format("Is \"{0}\" Palindrome : {1}", inputString, IsPalindrome(inputString)));	
   Console.WriteLine(String.Format("Is \"{0}\" Palindrome : {1}", inputString2, IsPalindrome(inputString2)));
   Console.WriteLine(String.Format("Is \"{0}\" Palindrome : {1}", inputString3, IsPalindrome(inputString3)));		
 }	  	
	
 public static bool IsPalindrome(string inputString)    
 {	          
    bool isPalindrome = false;  
   
    for (int i = 0, j = inputString.Length - 1; i < inputString.Length / 2; i++, j--)  
    {  
   	 if (inputString[i] != inputString[j])  
   	 {  
   		 isPalindrome = false;  
   		 break;  
   	 }  
   	 else  
   		 isPalindrome = true;  
    }  
  return isPalindrome;
 }	
}





Output: 

Is "NAYAN" Palindrome : True
Is "12321" Palindrome : True
Is "TechPointTech" Palindrome : False



Live Demo






No comments:

Post a Comment

Please do not enter any HTML. JavaScript or spam link in the comment box.