请参考、请斧正: 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);
} } }
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(); } } }
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);
}
}
}
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();
}
}
}