Write a c program to count vowel and consonant from a given string as like "I love Bangladesh"
#include<stdio.h>
main(){
int i , con=0 , vow=0 , space=0 , sentence=0;
char ch[]="i love bangladesh.";
for(i=0;ch[i]!='\0';i++){
if(ch[i]=='A' || ch[i]=='a' || ch[i]=='E' || ch[i]=='e' || ch[i]=='I' || ch[i]=='i' || ch[i]=='O' || ch[i]=='o' || ch[i]=='U' || ch[i]=='u'){
vow++;
}
else if(ch[i]==' '){
space++;
}
else if(ch[i]=='.'){
sentence++;
}
else{
con++;
}
}
printf("number of consonant is : %d \n",con);
printf("number of vowel is : %d \n",vow);
}
<< Go to Index Page >>
#include<stdio.h>
main(){
int i , con=0 , vow=0 , space=0 , sentence=0;
char ch[]="i love bangladesh.";
for(i=0;ch[i]!='\0';i++){
if(ch[i]=='A' || ch[i]=='a' || ch[i]=='E' || ch[i]=='e' || ch[i]=='I' || ch[i]=='i' || ch[i]=='O' || ch[i]=='o' || ch[i]=='U' || ch[i]=='u'){
vow++;
}
else if(ch[i]==' '){
space++;
}
else if(ch[i]=='.'){
sentence++;
}
else{
con++;
}
}
printf("number of consonant is : %d \n",con);
printf("number of vowel is : %d \n",vow);
}
<< Go to Index Page >>
//Find word sentence vowel consonent operator using file programming
উত্তরমুছুন#include
#include
int main()
{
FILE *source,*target;
char source_file[20],target_file[20],ch[250];
int i,v=0,c=0,a=0,w=1,s=0;
printf("Enter the file name to retrive string:");
gets(source_file);
source=fopen(source_file,"r");
fgets(ch, 255, (FILE*)source);
printf("3: %s\n", ch );
for(i=0;ch[i]!='\0';++i)
{
if(ch[i]=='a' || ch[i]=='e' || ch[i]=='i' || ch[i]=='o' || ch[i]=='u' ||
ch[i]=='A' || ch[i]=='E' || ch[i]=='I' || ch[i]=='O' || ch[i]=='U')
++v;
else if((ch[i]>='a' && ch[i]<='z')|| (ch[i]>='A' && ch[i]<='Z'))
++c;
else if(ch[i]=='+' || ch[i]=='-' || ch[i]=='*' || ch[i]=='/' || ch[i]=='%')
++a;
else if(ch[i]==' ')
++w;
else if(ch[i]=='.')
++s;
}
printf("Vowel: %d\n",v);
printf("Consonent: %d\n",c);
printf("Arithmetic Operator: %d\n",a);
printf("Word: %d\n",w);
printf("Sentence: %d\n",s);
printf("Enter a File name to Copy Answer:");
gets(target_file);
target=fopen(target_file,"w");
fprintf(target,"Vowel: %d\n Consonent: %d\nOperator: %d\nWord: %d\nSentence: %d",v,c,a,w,s);
fclose(target);
fclose(source);
return 0;
}