Programming Examples
Cpp program to accept 10 cities names, input character, display cities starting with it.
Write a cpp program to accept 10 cities' names and input character.
It should find and display all the cities whose names start with the entered character.
Solution
#include<iostream>
using namespace std;
int main()
{
char city[10][10],ch;
cout<<"Enter the cities"<<endl;
for(int a=0;a<10;a++)
{
cin.getline(city[a],10);
}
cout<<"Enter the first character of the string you want: "<<endl;
cin>>ch;
for(int a=0;a<10;a++)
{
if(city[a][0]==ch)
{
puts(city[a]);
}
}
return 0;
}
Output
Enter the cities:
kolkata
bombay
kanpur
delhi
agra
lucknow
allahabad
banglore
noida
ahmedabad
Enter the first character of the string you want:
a
agra
allahabad
ahmedabad