Monday, September 12, 2011

find whether the given string is a palindrome or not

TO find whether the given string is a palindrome or not */
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
    char string[90];
    int i,j,len,flag=0;
    clrscr();
    printf("\nEnter the string to be checked for Palindrome:\n");
    gets(string);
    len=strlen(string);   // or for(len=0;string[len]!='\0';len++);
    for(i=0,j=len-1;i<len/2;i++,j--)
      {
         if(string[i]!=string[j]) // check whether palindrome
        flag=1;
      }
    if(flag==1)
        printf("\nString is not a Palindrome");
    else
        printf("\nString is a Palindrome");
getch();
}

Change text line upper to lower case

#include<stdio.h>
#include<ctype.h>
#include<conio.h>
main(){
    char line[80];
    int i=0;
    clrscr();
    printf("\nenter a line of text in uppercase:");
    gets(line);
     //    scanf("%[^\n]",line);
    printf("uppercase of line of text converted to lowercase is \n");
    while(line[i]!='\0'){
    printf("%c",tolower(line[i]));
    i++;}
    printf("\n");
    getch();
    }

Popular 5 Posts Last 7 days