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

Status
Not open for further replies.

ja_mario14

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

user input in a same line.webp
 
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.webp

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.?
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 425
    Views
  • 2
    Participants
Last reply from:
ja_mario14

Online now

Members online
949
Guests online
1,588
Total visitors
2,537

Forum statistics

Threads
2,276,195
Posts
28,968,223
Members
1,231,159
Latest member
Cuong Pham
Back
Top