206k views
2 votes
Write a program that reads a series of strings andprints only those strings beginning with the letter "b."

User Kampta
by
4.6k points

1 Answer

3 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

char str[100][20];

int n;

cout<<"Strings you want to enter"<<endl;

cin>>n;

cout<<"enter n strings"<<endl;

for(int i=0;i<n;i++)

cin>>str[i];

for(int i=0;i<n;i++)

{

if((int)str[i][0]==98) //ascii value b is 98

cout<<str[i]<<endl;

}

return 0;

}

Step-by-step explanation:

The above written code is for printing the strings which starts with the letter b.

To check if the string starts with a letter b we are checking the ascii value 98 which corresponds to b and then printing those strings.

User Poonam
by
4.7k points