Write a program in C++ to accept a String and print the total no of vowels in it. Also print
the string in upper and lower case.........plz help me to get thiz answer i need it now
Answers
Program for counting vowels in a string:
int main()
{
char x[10];
int n,i,s=0;
cout<<"Enter any string\n";
cin>>x;
n=strlen(x);
for(i=0;i<n;++i)
{
if(x[i]=='a'||x[i]=='e'||x[i]=='i'||x[i]=='o'||x[i]=='u')
{
s=s+1;
}
}
cout<<s;
return 0;
}
This program will ask a string and after entering the string it will count the number of vowels and display the result.
e.g . the output will be :
Enter any string
education
5
Program for printing a string in uppercase and lowercase:
int main()
{
char str1 [30], temp[30];
cout < < "Enter the string:";
cin > > str1;
strcpy ( temp, str1);
cout < < "strupr ( temp ) : " < < strupr (temp) < < end1;
cout < < "strlwr (temp) : " < < strlwr ( temp) < < end1;
system("pause");
return 0;
}
Answer:
Program for counting vowels in a string:
int main()
{
char x[10];
int n,i,s=0;
cout<<""Enter any string\n"";
cin>>x;
n=strlen(x);
for(i=0;i<n;++i)
{
if(x[i]=='a'||x[i]=='e'||x[i]=='i'||x[i]=='o'||x[i]=='u')
{
s=s+1;
}
}
cout<<s;
return 0;
}
This program will ask a string and after entering the string it will count the number of vowels and display the result.
e.g . the output will be :
Enter any string
education
5
Program for printing a string in uppercase and lowercase:
int main()
{
char str1 [30], temp[30];
cout < < ""Enter the string:"";
cin > > str1;
strcpy ( temp, str1);
cout < < ""strupr ( temp ) : "" < < strupr (temp) < < end1;
cout < < ""strlwr (temp) : "" < < strlwr ( temp) < < end1;
system(""pause"");
return 0;
}