Answer to Question #188547 in C# for santhosh asrith

Question #188547

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 for-each loop to print all the data of the array.


1
Expert's answer
2021-05-03T07:53:52-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    class Program
    {


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


            Console.ReadLine();


        }
    }
}

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