1. Check whether given input is palindrome or not
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[50],str2[100];
int n,r;
printf("Enter the string");
gets(str1);
strcpy(str2,str1);
strrev(str1);
r=strcmp(str2,str1);
if(r==0)
{
printf("Palindrome ");
}
else
{
printf("Not palindrome");
}
getch();
}
Output
2. Program to check either given input is palindrome or not without using string handling function
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,flag=0,length=0;
char str1[100],str2[100];
printf("Enter the string");
gets(str1);
for(i=0;str1[i]!='\0';i++)
{
length++;
}
for(j=0,i=length-1;j<=length-1;j++,i--)
{
str2[j]=str1[i];
}
printf("Reverse of %s is %s\n",str1,str2);
for(i=0;i<=length-1;i++)
{
if(str2[i]!=str1[i])
{
flag=1;
break;
}
}
if(flag==1)
{
printf("%s is not palindrome",str1);
}
else
{
printf("%s is palindrome",str1);
}
getch();
}
3. Program to find the number of digits,consonants, vowels and space given by the user.
#include <stdio.h>
#include<conio.h>
int main()
{
char str[150];
int i;
int digit, space,vowels,consonant;
digit = space=vowels = consonant= 0;
printf("Enter the string");
gets(str );
sizeof(str);
for (int i = 0; str[i]!= '\0';i++)
{
if (str[i]=='a' || str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u' ||
str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]== 'U')
{
vowels++;
}
else if ((str[i]>= 'a'&& str[i]<= 'z')||(str[i] >= 'A'&& str[i]<= 'Z'))
{
consonant++;
}
else if (str[i] >= '0'&& str[i] <= '9')
{
digit++;
}
else if (str[i] == ' ')
{
space++;
}
}
printf("The Digits are%d\n",digit);
printf("The spaces are%d\n",space);
printf("The Vowels is %d\n",vowels);
printf("The Consonants is%d\n",consonant);
getch();
}
Output:
Here I haven't given space as you can see and there are 5 spaces and you can observe from above output fig.
Comments
Post a Comment