Friday, 18 August 2017

Assignment 7: Group C


//Aim: Write a C program that will check whether given string is palindrome or not.
Theory: palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar, NITIN Etc .
//Program:
#include <stdio.h>
#include <string.h>
int main()
{
char string1[20];
int i, length;
int flag = 0;
printf("Enter a string:");
scanf("%s", string1);
length = strlen(string1);
for(i=0;i<length;i++)
{
if(string1[i] != string1[length-i-1])
{
flag = 1;
break;
}
}
if (flag)
{
printf("%s is not a palindrome \n", string1);
}
else
{
printf("%s is a palindrome \n", string1);
}
return 0;

}

18 comments: