[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Basics

Home > Programs > Basics

7 / 279

Write a program using command line argument to input a word and check whether it is palindrome or not.

Answer:

#include 
#include 
#include 

void isPalindrome(char str[])
{
    int l = 0;
    int h = strlen(str) - 1;

    while (h > l)
    {
        if (str[l++] != str[h--])
        {
            printf("%s is Not Palindromen \r\n", str);
            return;
        }
    }
    printf("%s is palindromen\r\n", str);
}

int main(int argc, char * argv[])
{
  if (argc == 1 || argc > 2)
  {
    printf("Enter String \r\n");
    exit(0);
  }

  isPalindrome(argv[1]);
return 0;
         

Asked In :: TCS

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here: