新手上路,请各位大神,交一下如何做这三道题[em07]
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { double sum = 0; for (int i = 1; i <= 100; i++) { sum += (1.0 / i); } Console.WriteLine("1/1 + 1/2 + 1/3 + 1/4 + ... + 1/100 = " + sum); int s = 0; int x = 1; for (int i = 1; i <= 10000; i += x) { x += 2; s += i; } Console.WriteLine("1 + 4 + 9 + 16 + ... + 10000 = " + s); sum = 0; x = 1; for (int i = 0; i < 100; i++) { sum += (4.0 / x); x += 2; } Console.WriteLine("4/1 + 4/3 + 4/5 + 4/7 + ... 前100项之和 = " + sum); Console.Read(); } } }
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { double sum = 0; for (int i = 1; i <= 100; i++) { sum += (1.0 / i); } Console.WriteLine("1/1 + 1/2 + 1/3 + 1/4 + ... + 1/100 = " + sum); int s = 0; int x = 1; for (int i = 1; i <= 10000; i += x) { x += 2; s += i; } Console.WriteLine("1 + 4 + 9 + 16 + ... + 10000 = " + s); sum = 0; x = 1; for (int i = 1; i <= 100; i++) { if (i % 2 == 0) { sum -= (4.0 / x); } else { sum += (4.0 / x); } x += 2; } Console.WriteLine("4/1 - 4/3 + 4/5 - 4/7 + ... 前100项之和 = " + sum); Console.Read(); } } }