设计一个程序,让用户输入5个数字,计算并显示出正数,负数和零的个数。   大家谁帮忙写一下代码呀,谢谢啦,第一次来这个论坛哈~

解决方案 »

  1.   

    请参考、请斧正:
    using System;namespace myFirst
    {
        class Program
        {
            static void Main(string[] args)
            {
                int a = 0;
                int b = 0;
                int c = 0;
                int[] arr = new int[5];
                for (int i = 0; i < 5; i++)
    {
        arr[i] = Int32.Parse(Console .ReadLine ()); 
    }   
                foreach (int i in arr)
                {
                    if (i > 0)
                    {
                        a++;
                    }
                    else if (i == 0)
                    {
                        b++;
                    }
                    else if (i < 0)
                    {
                        c++;
                    }
                }
                Console.WriteLine(a);
                Console.WriteLine(b);
                Console.WriteLine(c);
                
            }
        }
    }
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication27
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] R = new int[3];
                String[] S = new String[3] { "负数", "零", "正数" };            for (int i = 0; i < 5; i++)
                    R[Math.Sign(int.Parse(Console.ReadLine())) + 1]++;
                Console.WriteLine("---------");
                for (int i = 0; i < R.Length; i++)
                    Console.WriteLine(S[i] + ":" + R[i]);
                Console.Read();
            }
        }
    }