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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz