C program example for palindrome:
What is palindrome?
- When a number or word or a phrase or a sequence of characters which resembles the same while reading them from backward are called palindrome.
- Palindrome examples: 2882, madam, noon, level.
- The above examples resemble as same while reading them from backward also. If you read number “2882” from backward, it is same as “2882”. If you read the word “madam” from backward, it is same as “madam”
Example C program to check a number whether it is palindrome or not:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <stdio.h> int main() { int number, t, rev=0, rmndr; printf("Please enter a number to check Palindrome : "); scanf("%d",&number); printf("\nEntered number: %d", number); t = number; while (number > 0) { rmndr = number%10; rev = rev*10 + rmndr; number = number/10; } printf("\nReversed number: %d", rev); if(t == rev) { printf("\nEntered number %d is a palindrome", t); } else { printf("\nEntered number %d is not a palindrome", t); } return 0; } |
Output of C program for palindrome:
Please enter a number to check Palindrome : 656
Entered number: 656 Reversed number: 656 Entered number 656 is a palindrome |
Example C program to check a word whether it is palindrome or not:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <stdio.h> #include <string.h> int main() { char str[], i=0; int str_len; printf("Please enter a word to check Palindrome : "); scanf("%s",str); printf("\nEntered word: %s", str); while(1) { str_len = strlen(str) - (i+1); if (str[i] == str[str_len]) { if (i == str_len || i+1 == str_len) { printf("\nEntered word \"%s\" is a palindrome", str); break; } i = i+1; } else { printf("\nEntered word \"%s\" is not a palindrome", str); break; } } return 0; } |
Output of C program for palindrome:
Please enter a word to check Palindrome : madam
Entered word: madam Entered word “madam” is a palindrome |
OTHER C PROGRAMS:
- C program for prime number
- C program for factorial
- C program for fibonacci series
- C program for palindrome
- C program for swapping 2 numbers with and without temp variables
- C program to find leap year
- C program to find armstrong number
- C program to find simple and compound interest
- C program to find largest of given 3 numbers
- C program to find smallest of given 3 numbers
- C program to convert lower case into upper case and vice versa
- C program to find sum and average of given 3 numbers
- C program to sum up all individual digits
- C program to reverse given number
- C program to reverse given string
- C program to find strong number
- C program to find square and cube of given number
- C program to print hello world without using semi colon
- C program to sort given names in alphabetical order
- C program to copy content of one file to another
- C program to sort given numbers in ascending order
- C program to sort given numbers in descending order
- C program to search given number in an array
- C program for recursive function
- C program for calculator application
- C program for bank application
- C program to check given number is perfect number or not
- C program to find array size
- C program to find whether given character vowel or not
- C program to check whether given number is positive or negative
- C program to find sum of n numbers
- C program to compare 2 numbers without if statement
- C program to generate random numbers
- C program to compare 2 arrays whether they are equal or not
- C program to print number from 1 to 500 without using any loop conditions
- C program to insert an element into an array
- C program to delete an element from an array
- C program to find hcf (gcd) and lcm
- C program to print diamond pattern
- C program to print pascal triangle
- C program to add two complex numbers
- C program for matrix addition
- C program for matrix multiplication
- C program for bubble sort
- C program for insertion sort
- C program for selection sort