What's new

C# Paano po makakagawa ng User input in a same line gamit ang 3x3 array?

ja_mario14

Addict
Joined
Apr 1, 2022
Posts
102
Reaction
16
Points
89
Pahelp po Paano po makakagawa ng User input in a same line gamit ang 3x3 array?

user input in a same line.png
 

Attachments

C#:
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] input = new int[3, 3];
            string[] rowName = new string[3] { "first","second","third"};

            for (int row = 0; row < 3; row++)
            {
                Console.WriteLine(String.Format("Enter three numbers in {0} row separated by space", rowName[row]));
                string[] s = Console.ReadLine().Split();

                int index = 0;
                for (int inputIndex=0;inputIndex<3;inputIndex++)
                {
                    input[row, index] = int.Parse(s[inputIndex]);
                    index++;
                }
            }

            //only if output is needed
            foreach(int item in input)
            {
                Console.Write(item.ToString() + " ");
            }

            Console.ReadKey(true);

        }


    }
}
 
Good morning sir, ganito po sana yung kakalabasan sir.

hindi ko lang po magawa yung sa first input yung maglalagay ng 3 numbers sa kada row na nasa isang line.

after po makapag input ng 9 numbers sa 3 rows in a same line iddisplay po at isa-sum yung nainput sa 3 rows.

user input in a same line.png

C#:
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] input = new int[3, 3];
            string[] rowName = new string[3] { "first","second","third"};

            for (int row = 0; row < 3; row++)
            {
                Console.WriteLine(String.Format("Enter three numbers in {0} row separated by space", rowName[row]));
                string[] s = Console.ReadLine().Split();

                int index = 0;
                for (int inputIndex=0;inputIndex<3;inputIndex++)
                {
                    input[row, index] = int.Parse(s[inputIndex]);
                    index++;
                }
            }

            //only if output is needed
            foreach(int item in input)
            {
                Console.Write(item.ToString() + " ");
            }

            Console.ReadKey(true);

        }


    }
}



sir okay na po pala, naayos ko na po. maraming salamat po sir.
wala pong check for mark as solution.?
 

Attachments

Last edited:
Back
Top