using System;
namespace C4_8
{
public class Progarm
{
public static void Main()
{
int x = 0; //統計奇數
int y = 0; //統計偶數
//定義並初始話一個一維陣列
int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15 };
//提取陣列中的整數
foreach (int i in arr)
{
if (i % 2 == 0)
{
y++;
}
else
{
x++;
}
}
Console.WriteLine("奇數個數:{0}\n偶數個數:{1}", x, y);
}
}
}
沒有留言:
張貼留言