##我已經使用數組添加了數字 -
int[] num = new int[] {1, 25, 1, 55, 1};
foreach(int j in num) { if (j == 1) { cal++; } }
using System; public class Demo { public static void Main() { int cal = 0; int[] num = new int[] {1, 25, 1, 55, 1}; Console.WriteLine("Numbers:"); for (int i = 0; i < 5; i++) { Console.WriteLine(num[i]); } foreach (int j in num) { if (j == 1) { cal++; } } Console.WriteLine("Number of 1's: "); Console.WriteLine(cal); Console.ReadLine(); } }
以上是C#程式:計算輸入數字中1的個數的詳細內容。更多資訊請關注PHP中文網其他相關文章!