บทความล่าสุด

31 สิงหาคม 2554

Lab#09

งานทดลองในชั่วโมง
โจทย์ตอบคำถาม

1. int[,] num1 = new int[100];
2. float[,] num2 = new float[75];
3. char[,] char1 = new char[250];
4. string[,] string1 = new string[350];
5. int[,] num3 = new int[20, 30];
6. float[,] num4 = new float[10, 10];
7. char[,] char2 = new char[3, 20];
8. string[,] string2 = new string[10, 30];






โจทย์เขียนโปรแกรม

9. int[] score = new int[1000];
    for (int i = 0; i < 1000; i++)
                score[i] = 777;

10. int[,] tabel1 = new int[50,100];
   for(int i = 0; i < 50; i++)
   {
       for(int j = 0; j < 100; j++)
       {
           tabel1[i,j] = i;
           Console.Write(i + " ");
       }
       Console.WriteLine("\n");
   }






การบ้าน
ข้อ 1
            int num1;
            Console.Write("Please intput number : ");
            num1 = int.Parse(Console.ReadLine());
            for (int i = 0; i < num1; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    Console.Write(num1);
                }
                Console.WriteLine();
            }

ข้อ2

            int num1;
            Console.Write("Please input number of student : ");
            num1 = int.Parse(Console.ReadLine());
            string[] stName = new string[num1];
            float[] stScore = new float[num1];
            for (int i = 0; i < num1; i++)
            {
                Console.Write("student"+(i+1)+"'s name : ");
                stName[i] = Console.ReadLine();
                Console.Write("student" + (i+1) + "'s Score : ");
                stScore[i] = float.Parse(Console.ReadLine());
            }

ข้อ3 

                int arraySize;
                float sum=0;
              
                Console.Write("Please input array size :");
                arraySize = int.Parse(Console.ReadLine());

                float[] array1 = new float[arraySize];
                for (int i = 0; i < arraySize; i++)
                {
                    back:
                    Console.Write("Please number "+(i+1)+": ");
                    array1[i] = float.Parse(Console.ReadLine());
                    if (array1[i] > 0 && array1[i] < 100)
                    {
                        array1[i] = array1[i];
                        sum = sum + array1[i];
                    }
                    else
                    {
                        Console.WriteLine("Invalid number! Please input again.");
                        goto back;
                    }
                }
                Console.WriteLine("AVARAGE = " + (sum / arraySize));

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

แสดงความเห็นเกี่ยวกับบทความตรงนี้นะ ^^