Answers for "palindrome string program in c using array"

C
2

palindrome string program in c

#include <stdio.h>
#include <string.h>
int main()
{

     char str[80];
     int length;
     printf("\nEnter a string to check if it's a palindrome: ");
     scanf("%s", str);     // string input
     length = strlen(str); // finding the string length
     int i, j, count;
     for (i = 0, j = length - 1, count = 0; i < length; i++, j--)
     {
          // matching string first character with the string last character
          if (str[i] == str[j])
          {
               count++; // if character match, increasing count by one.
          }
     }
     if (count == length) // if count == length, then the string is a palindrome.
     {
          printf("'%s' is a palindrome.\n", str);
     }
     else // otherwise the string is not a palindrome.
     {
          printf("'%s' is not a palindrome.\n", str);
     }
     return 0;
}
Posted by: Guest on July-04-2021
1

check if string is palindrome in c

// this is for string

#include <stdio.h>
#include <string.h>

void main()
{
  char a[100], b[100];

  printf("Enter a string to check if it's a palindrome: ");
  gets(a);

  strcpy(b, a);

  if (strcmp(a, b) == 0)
    printf("\nThe string is palindrome.\n");

  else
    printf("\nThe string is not palindrome.\n");

  getch();
}
Posted by: Guest on June-23-2021
0

palindrome in c using function

#include <stdio.h>
#include <conio.h>

int palindrome (int num);

void main()
{
    int n, ret;
    printf("Enter the number: ");
    scanf("%d",&n);

    ret = palindrome(n);

    if (ret == n)
        printf("\nPalindrome\n");
    else
        printf("\nNot Palindrome\n");
}

int palindrome(int num)
{
    int rem, rev=0;

    while (num!=0)
    {
        rem = num % 10;
        rev = rev * 10 + rem;
        num /= 10;
    }

    return rev;
}
Posted by: Guest on June-23-2021

Code answers related to "palindrome string program in c using array"

Code answers related to "C"

Browse Popular Code Answers by Language