Write a C program to find the length of the given string.
SOURCE CODE:
/*Program to find length of given string.*/
#include<stdio.h>
#include<string.h>
void main()
{
char str[30];
int i,len=0;
clrscr();
printf("Enter string1:\n");
gets(str);
for(i=0;str[i]!='\0';i++)
len++;
printf("Length of given string is %d",len);
}
OUTPUT:
Write a C program to check whether the given string is palindrome or not.
SOURCE CODE:
/*Program to find whether a given string is palindrome or not.*/
#include<stdio.h>
#include<conio.h>
void main()
{
char str[30];
int i,j,len=0,flag=0;
clrscr();
printf("Enter string1:\n");
gets(str);
for(i=0;str[i]!='\0';i++)
len++;
for(i=len-1,j=0;i>=j;i--,j++)
{
if(str[i]!=str[j])
{
flag=1;
break;
}
}
if(flag==1)
printf("\nString is not palindrome.");
else
printf("\nString is palindrome.");
}
OUTPUT: