Answer to Question #188999 in C# for CHANDRASENA REDDY

Question #188999

Define a single dimension array of strings to hold the name of City. Accept some values from the user and store them in the array. Use foreach loop to print all the data of the array. 


1
Expert's answer
2021-05-09T23:37:55-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    class Program
    {


        static void Main(string[] args)
        {


            int numberCities;
            Console.Write("Enter the number of city: ");
            numberCities = int.Parse(Console.ReadLine());
            //Define a single dimension array of strings to hold the name of City.
            string[] cites = new string[numberCities];
            //Accept some values from the user and store them in the array. 
            for (int i = 0; i < numberCities; i++)
            {
                Console.Write("Enter a city {0}: ", (i + 1));
                cites[i] = Console.ReadLine();
            }
            //Use foreach loop to print all the data of the array.
            Console.WriteLine("\nAll cities are:");
            foreach (var c in cites)
            {
                Console.WriteLine(c);
            }


            Console.ReadKey();


        }
    }
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS