Answer to Question #272346 in C# for Ann

Question #272346

Make a function that takes 2 integer and lists out all the numbers from the 1st number until the 2nd number


1
Expert's answer
2021-11-27T11:34:40-0500
using System;

namespace ConsoleApp1
{
    class Program
    {
        public static void List(int x, int y)
        {
            Console.WriteLine("List:");
            for (int i = x; i <= y; i++)
            {
                Console.WriteLine(i);
            }
        }

        static void Main(string[] args)
        {
            int x, y;
            Console.Write("Enter X: ");
            string str = Console.ReadLine();
            if (!int.TryParse(str, out x))
                Console.WriteLine("Bad number.");

            Console.Write("Enter Y: ");
            str = Console.ReadLine();
            if (!int.TryParse(str, out y))
                Console.WriteLine("Bad number.");

            List(x, y);
        }
    }
}

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