在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
求1-100之间所有奇数整数和: 1 class Program 2 { 3 static void Main(string[] args) 4 { 5 int sum= GetOdd(1,100); 6 Console.WriteLine("1-100之间所有奇数整数和{0}",sum); 7 Console.ReadKey(); 8 } 9 /// <summary> 10 /// 奇数和 11 /// </summary> 12 /// <param name="p1"></param> 13 /// <param name="p2"></param> 14 /// <returns></returns> 15 private static int GetOdd(int p1, int p2) 16 { 17 int sum = 0; 18 for (int i = p1; i <= p2; i++) 19 { 20 if (i%2!=0) 21 { 22 sum += i; 23 } 24 } 25 return sum; 26 } 27 }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论