palindrome string program in c

Solutions on MaxInterview for palindrome string program in c by the best coders in the world

showing results for - "palindrome string program in c"
Deacon
16 Sep 2020
1#include <stdio.h>
2#include <conio.h>
3
4void main()
5{
6
7    int n,i,r=0;
8    
9    printf("Enter a number: ");
10    scanf("%d",&n);
11    
12    for(i=n;i!=0;i)
13    {
14        r=r*10;
15        r=r+ i%10;
16        i=i/10;
17    }
18    
19    if(r==n)
20        printf("palindrome");
21    else
22        printf("Not palindrome");
23}
Enrico
02 Nov 2018
1#include <stdio.h>
2#include <string.h>
3int main()
4{
5
6     char str[80];
7     int length;
8     printf("\nEnter a string to check if it's a palindrome: ");
9     scanf("%s", str);     // string input
10     length = strlen(str); // finding the string length
11     int i, j, count;
12     for (i = 0, j = length - 1, count = 0; i < length; i++, j--)
13     {
14          // matching string first character with the string last character
15          if (str[i] == str[j])
16          {
17               count++; // if character match, increasing count by one.
18          }
19     }
20     if (count == length) // if count == length, then the string is a palindrome.
21     {
22          printf("'%s' is a palindrome.\n", str);
23     }
24     else // otherwise the string is not a palindrome.
25     {
26          printf("'%s' is not a palindrome.\n", str);
27     }
28     return 0;
29}
Vanessa
10 Jan 2021
1// this is for string
2
3#include <stdio.h>
4#include <string.h>
5
6void main()
7{
8  char a[100], b[100];
9
10  printf("Enter a string to check if it's a palindrome: ");
11  gets(a);
12
13  strcpy(b, a);
14
15  if (strcmp(a, b) == 0)
16    printf("\nThe string is palindrome.\n");
17
18  else
19    printf("\nThe string is not palindrome.\n");
20
21  getch();
22}
23
Alan
19 Apr 2018
1#include <stdio.h>
2int main() {
3    int n, reversedN = 0, remainder, originalN;
4    printf("Enter an integer: ");
5    scanf("%d", &n);
6    originalN = n;
7
8    // reversed integer is stored in reversedN
9    while (n != 0) {
10        remainder = n % 10;
11        reversedN = reversedN * 10 + remainder;
12        n /= 10;
13    }
14
15    // palindrome if orignalN and reversedN are equal
16    if (originalN == reversedN)
17        printf("%d is a palindrome.", originalN);
18    else
19        printf("%d is not a palindrome.", originalN);
20
21    return 0;
22}
23
24
Cheyenne
04 Jan 2018
1#include <stdio.h>
2#include <conio.h>
3
4int palindrome (int num);
5
6void main()
7{
8    int n, ret;
9    printf("Enter the number: ");
10    scanf("%d",&n);
11
12    ret = palindrome(n);
13
14    if (ret == n)
15        printf("\nPalindrome\n");
16    else
17        printf("\nNot Palindrome\n");
18}
19
20int palindrome(int num)
21{
22    int rem, rev=0;
23
24    while (num!=0)
25    {
26        rem = num % 10;
27        rev = rev * 10 + rem;
28        num /= 10;
29    }
30
31    return rev;
32}
33
similar questions
queries leading to this page
palindrome string program in c