Example for character functions:
/* Program to count the number of vowels */
# include < stdio.h >
main ( )
{
char word[30];
int j=0, a=0, e=0, o=0, u=0, i=0;
printf( " \n Enter any word " );
scanf( "%s",word );
while( word[j] != '\0' )
{
switch ( word[j] )
{
case 'a' :
case 'A' : a++; break;
case 'e' :
case 'E' : e++; break;
case 'i' :
case 'I' : i++; break;
case 'o' :
case 'O' : o++; break;
case 'u' :
case 'U' : u++; break;
}
j++;
}
printf( " \n a=%d \n e=%d \n i=%d \n o=%d \n u=%d ",a,e,i,o,u );
}
/* Program to count the number of vowels */
# include < stdio.h >
main ( )
{
char word[30];
int j=0, a=0, e=0, o=0, u=0, i=0;
printf( " \n Enter any word " );
scanf( "%s",word );
while( word[j] != '\0' )
{
switch ( word[j] )
{
case 'a' :
case 'A' : a++; break;
case 'e' :
case 'E' : e++; break;
case 'i' :
case 'I' : i++; break;
case 'o' :
case 'O' : o++; break;
case 'u' :
case 'U' : u++; break;
}
j++;
}
printf( " \n a=%d \n e=%d \n i=%d \n o=%d \n u=%d ",a,e,i,o,u );
}
Comments
Post a Comment