Thursday, December 2, 2010

Total Number of Consonants in a String

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int c=0,i,l,p;
char a[10];
clrscr();
printf("program that gives total number of consonants in a string");
printf("\n\n\n\t\t------------INPUT-------------");
printf("\n\nenter any string");//taking input from the user
scanf("%s",&a);
l=strlen(a);
for(i=0;i
{
if(a[i]=='a' || a[i]=='e' || a[i]=='o' || a[i]=='i' || a[i]=='u')
c++;
}
p=l-c;
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe total no. of consonants in the string are=%d",p);//printing output
getch();
}

Use of Strlen() Function

#include<stdio.h>

#include<string.h>

void main(void)

{

char str[31];

int len;

printf("\nEnter any String");

gets(str);

len=strlen(str);

printf("\nNumber of Character in%s=%d\n",str,len);

}