Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Abstract Classes

Abstract Classes Logo Abstract Classes Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Polls
  • Add group
  • Buy Points
  • Questions
  • Pending questions
  • Notifications
    • sonali10 has voted up your question.September 24, 2024 at 2:47 pm
    • Abstract Classes has answered your question.September 20, 2024 at 2:13 pm
    • The administrator approved your question.September 20, 2024 at 2:11 pm
    • banu has voted up your question.August 20, 2024 at 3:29 pm
    • banu has voted down your question.August 20, 2024 at 3:29 pm
    • Show all notifications.
  • Messages
  • User Questions
  • Asked Questions
  • Answers
  • Best Answers
Home/ Questions/Q 58555
Next
In Process
Himanshu Kulshreshtha
Himanshu KulshreshthaElite Author
Asked: May 22, 20242024-05-22T10:10:08+05:30 2024-05-22T10:10:08+05:30In: INFORMATION TECHNOLOGY

Write a program in C language to check that a string entered by the user is Palindrome or not.

Write a program in C language to check that a string entered by the user is Palindrome or not.

CITL-001
  • 0
  • 11
  • 20
  • 0
  • 0
Share
  • Facebook

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. Himanshu Kulshreshtha Elite Author
      2024-05-22T10:10:44+05:30Added an answer on May 22, 2024 at 10:10 am

      To check whether a string entered by the user is a palindrome or not in C language, follow these steps:

      1. Prompt the user to enter a string.
      2. Read the string input from the user and store it in a character array.
      3. Define two pointers, one pointing to the beginning of the string (let's call it start) and the other pointing to the end of the string (let's call it end).
      4. Compare characters at start and end positions iteratively until start becomes greater than or equal to end.
      5. If at any point the characters at start and end positions are not equal, the string is not a palindrome. Otherwise, continue comparing characters until the pointers meet.
      6. If all characters match, the string is a palindrome.

      Here's the C code implementing the above logic:

      #include <stdio.h>
      #include <string.h>
      #include <ctype.h>
      
      int main() {
          char str[100];
          int start, end, isPalindrome = 1; // Assume palindrome initially
      
          printf("Enter a string: ");
          fgets(str, sizeof(str), stdin);
      
          // Remove newline character at the end of the input string
          str[strcspn(str, "\n")] = '\0';
      
          // Convert the string to lowercase for case-insensitive comparison
          for (int i = 0; str[i]; i++) {
              str[i] = tolower(str[i]);
          }
      
          // Initialize start and end pointers
          start = 0;
          end = strlen(str) - 1;
      
          // Compare characters at start and end positions
          while (start < end) {
              if (str[start] != str[end]) {
                  isPalindrome = 0; // Not a palindrome
                  break;
              }
              start++;
              end--;
          }
      
          if (isPalindrome) {
              printf("The string is a palindrome.\n");
          } else {
              printf("The string is not a palindrome.\n");
          }
      
          return 0;
      }
      

      This program prompts the user to enter a string, reads the input string, and then checks whether it is a palindrome or not. It performs case-insensitive comparison by converting the string to lowercase. Finally, it prints the result indicating whether the string is a palindrome or not.

      • 0
      • Share
        Share
        • Share onFacebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Related Questions

    • Create an invitation card of your birthday party in MS-Word. b) Exhibit the use of Mail merge in MS word, ...
    • Write HTML code to display a webpage for a hospital and create a web form for taking online appointment of ...
    • Create a database in MS-Access for a hospital, which is having the following database fields : • Doctor ID, Doctor ...
    • Write a Java applet which converts metres into kilometres and centimetres as given by the user.
    • Write a program in 'C' language, which accepts a text string from a user and prints its reverse order.
    • IGNOU wants to deliver CIT programme in multimedia form. Propose a plan to develop a CIT block in multimedia form. ...
    • Design a web page which uses two frames, the left frame are further divided into two frames horizontally. The upper ...
    • What is Computer Vision? What are the technical challenges in the context of computer vision? Explain.

    Sidebar

    Ask A Question

    Stats

    • Questions 21k
    • Answers 21k
    • Popular
    • Tags
    • Pushkar Kumar

      Bachelor of Science (Honours) Anthropology (BSCANH) | IGNOU

      • 0 Comments
    • Pushkar Kumar

      Bachelor of Arts (BAM) | IGNOU

      • 0 Comments
    • Pushkar Kumar

      Bachelor of Science (BSCM) | IGNOU

      • 0 Comments
    • Pushkar Kumar

      Bachelor of Arts(Economics) (BAFEC) | IGNOU

      • 0 Comments
    • Pushkar Kumar

      Bachelor of Arts(English) (BAFEG) | IGNOU

      • 0 Comments
    Academic Writing Academic Writing Help BEGS-183 BEGS-183 Solved Assignment Critical Reading Critical Reading Techniques Family & Lineage Generational Conflict Historical Fiction Hybridity & Culture IGNOU Solved Assignments IGNOU Study Guides IGNOU Writing and Study Skills Loss & Displacement Magical Realism Narrative Experimentation Nationalism & Memory Partition Trauma Postcolonial Identity Research Methods Research Skills Study Skills Writing Skills

    Users

    Arindom Roy

    Arindom Roy

    • 102 Questions
    • 104 Answers
    Manish Kumar

    Manish Kumar

    • 49 Questions
    • 48 Answers
    Pushkar Kumar

    Pushkar Kumar

    • 57 Questions
    • 56 Answers
    Gaurav

    Gaurav

    • 535 Questions
    • 534 Answers
    Bhulu Aich

    Bhulu Aich

    • 2 Questions
    • 0 Answers
    Exclusive Author
    Ramakant Sharma

    Ramakant Sharma

    • 8k Questions
    • 7k Answers
    Ink Innovator
    Himanshu Kulshreshtha

    Himanshu Kulshreshtha

    • 10k Questions
    • 11k Answers
    Elite Author
    N.K. Sharma

    N.K. Sharma

    • 930 Questions
    • 2 Answers

    Explore

    • Home
    • Polls
    • Add group
    • Buy Points
    • Questions
    • Pending questions
    • Notifications
      • sonali10 has voted up your question.September 24, 2024 at 2:47 pm
      • Abstract Classes has answered your question.September 20, 2024 at 2:13 pm
      • The administrator approved your question.September 20, 2024 at 2:11 pm
      • banu has voted up your question.August 20, 2024 at 3:29 pm
      • banu has voted down your question.August 20, 2024 at 3:29 pm
      • Show all notifications.
    • Messages
    • User Questions
    • Asked Questions
    • Answers
    • Best Answers

    Footer

    Abstract Classes

    Abstract Classes

    Abstract Classes is a dynamic educational platform designed to foster a community of inquiry and learning. As a dedicated social questions & answers engine, we aim to establish a thriving network where students can connect with experts and peers to exchange knowledge, solve problems, and enhance their understanding on a wide range of subjects.

    About Us

    • Meet Our Team
    • Contact Us
    • About Us

    Legal Terms

    • Privacy Policy
    • Community Guidelines
    • Terms of Service
    • FAQ (Frequently Asked Questions)

    © Abstract Classes. All rights reserved.