//没有参数,没有返回值namespace _100以内奇数和 { class Program { public void jishu() { int sum = 0; for (int i = 1; i <= 100; i++) { if (i % 2 != 0) { sum += i; } } Console.WriteLine(sum); } static void Main(string[] args) { Program hanshu = new Program(); //100以内奇数的和 //int sum = 0; //for (int i = 1; i <= 100; i++) //{ // if (i % 2 != 0) // { // sum += i; // } //} //Console.WriteLine(sum); hanshu.jishu(); Console.ReadLine(); } } }
时间: 2024-10-06 04:51:42