Answer to Question #238622 in C# for MALATI Woyengimies

Question #238622
Write a program that prompts the user to input a four-digit positive integer. The program then outputs
the digits of the number, one digit per line. For example, if the input is 3245, the output is:
3
2
4
5
1
Expert's answer
2021-09-17T12:08:51-0400
using System;

namespace Test
{
    class InputTest
    {
        static int Main()
        {
            int number;
            Console.Write("Input a four-digit positive integer: ");
            string line = Console.ReadLine();

                if(!int.TryParse(line, out number) || number < 1000 || number > 9999)
                {
                    Console.WriteLine("Bad input");
                    return 1;
                }

            Console.WriteLine((number / 1000) % 10);
            Console.WriteLine((number / 100) % 10);
            Console.WriteLine((number / 10) % 10);
            Console.WriteLine(number % 10);

            return 0;
        }
    }
}

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