Showing posts with label palindrome. Show all posts
Showing posts with label palindrome. Show all posts

C and C++ Programs to Reverse a Number

This post includes a C program and a C++ program to reverse a given number. That is, to reverse the order of digits. If 543 is entered, it will be displayed as 345.

C Program:

#include<stdio.h>
main()
{

C Program to Check Whether a Given String is Palindrome or Not

Here i am writing two different programs two check whether an input string is palindrome or not. The first program checks the string manually character by chatter from both ends. The other program make use of a string function strrev() (under string.h) to reverse the string. Therefore, the second program is more compact.

Program 1:

#include<stdio.h>

#include<string.h>

void main()

{

char a[20];

int i, len;

printf("\nEnter the string:\n");

gets(a);

len = strlen(a);

for (i = 0; i < len / 2; i++)

{

if (a[i] != a[len - i - 1])

break;

}