Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

Program Discussion :: Basics

Home > Programs > Basics

8 / 248

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: