Showing posts with label Plaindrome. Show all posts
Showing posts with label Plaindrome. Show all posts

C Program Palindrom: reliefpfeiler, otto

How to write a C Program Palindrom: reliefpfeiler, otto ?


Solution:

#include <stdio.h>
#include <stdlib.h>
// Palindrom: reliefpfeiler, otto

int isPalindrom_iter(char *pal, int strlen) {
int i;
for (i = 0; i < strlen; i++) if (pal[i] != pal[strlen - i-1]) return 0;
return 1;
}

int isPalindrom_rek(char *pal, int strlen) {
if (strlen < 1) return 1;
return (pal[0] == pal[strlen - 1]) && isPalindrom_rek(pal + 1, strlen - 2);
}



int main(void) {
char *jn[] = { "no", "yes" };
printf("Is Palindrom, %s!\n", jn[isPalindrom_iter("reliefpfeiler", 13)]);
printf("Is Palindrom, %s!\n", jn[isPalindrom_rek("reliefpfeiler", 13)]);
system("pause");

return 0;
}

C Program to Check Given String is Palindrome or Not

How to write a C Program to Check Given String is Palindrome or Not in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. void main()
  5. {
  6.  char a[10],b[10];
  7.  clrscr();
  8.  printf("\nEnter a string: ");
  9.  gets(a);
  10.  strcpy(b,a);
  11.  strrev(b);
  12.  if(strcmp(a,b)==0)
  13.  {
  14.   printf("%s is palindrom",a);
  15.  }
  16.  else
  17.  {
  18.   printf("%s is not palindrom",a);
  19.  }
  20.  getch();
  21. }

Input a Number and Check if it's Palindrome or not C Program

How to write a C Program to input a number and check if it's palindrome or not in C Programming Language ?



//Program to input a number and check if it's palindrome or not.
#include<stdio.h>
#include<conio.h>

void main()
{
int number,

clrscr();

printf("Enter number: ");
scanf("%d", &number);

while(number != 0) {
number % 10);
number = number / 10;
}

getch();
}

check if the number is a palindrome number or not.