int i = 1, oddsum = 0;
for (; i <= 100; i+=2)
{
oddsum += i;
}
Console.WriteLine(oddsum);//1-100奇数求和
int[] nums ={12,34,11,56,77,79,35};
int odd=0,even=0;
foreach(int k in nums)
{
if (k % 2 == 0)
odd++;
else even++;
}
Console.WriteLine(odd);//数组奇数个数
Console.WriteLine(even);//数组偶数个数
C#for和forench用法
最新推荐文章于 2024-08-16 00:34:04 发布