Subscribe to Feeds

Send Your Projects To georgepj@hotmail.com

We'll Publish It With Your Name :-)

Programs Can Also Be Downloaded From The Folders Below....[Or Scroll Down]

String - Sort and Check for Palindrome

Click Here To Download C File Of This Program

 //PROGRAM TO SORT GIVEN STRINGS & CHECK FOR PALINDROME  
//Downloaded from www.c4cprog.co.nr
#include<conio.h>
#include<string.h>
void sort(char st[50][20],int n)
{ int i,j;
char k[50];
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(strcmp(st[j],st[j+1])>1)
{
strcpy(k,st[j]);
strcpy(st[j],st[j+1]);
strcpy(st[j+1],k);
}
for(i=0;i<n;i++)
{
printf("\nString %d :",i+1);
printf("%s",st[i]);
}
}
void palindrome(char st[50][20],int n)
{
int i,j,r=0;
char k[50];
for(i=0;i<n;i++)
{
strcpy(k,st[i]);
strrev(k);
if(strcmp(st[i],k)==0)
{
printf("\n\nString %d is Palindrome",i+1);
r++;
}}
if(r==0)
printf("\n\nNo Palindromes !!!");
}
void main()
{
int op,n,i;
char st[50][20],k[50],v;
do{
clrscr();
printf("\nEnter The no of Strings : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nString %d :",i+1);
scanf("%s",&st[i]);
}
printf("\nOptions\n\n1.Sort String\n2.Check For Palindrome\n\nEnter Option :");
scanf("%d",&op);
switch(op)
{
case 1:
sort(st,n);
break;
case 2:
palindrome(st,n);
break;
default:
printf("\n\nWRONG CHOICE !!!");
break;
}
printf("\n\nPress 'e' To EXIT & Any Other Key To Continue : ");
scanf(" %c",&v);
}while(v!='e');
}
/*
OUTPUT
Enter The no of Strings : 3
String 1 :Testing
String 2 :The
String 3 :Program
Options
1.Sort String
2.Check For Palindrome
Enter Option :1
String 1 :Program
String 2 :Testing
String 3 :The
Press 'e' To EXIT & Any Other Key To Continue :c
Enter The no of Strings : 3
String 1 :MALAYALAM
String 2 :IS
String 3 :PALINDROME
Options
1.Sort String
2.Check For Palindrome
Enter Option :2
String 1 is Palindrome
Press 'e' To EXIT & Any Other Key To Continue : e
*/

0 comments:

Post a Comment