Menghitung Deret barisan Bilangan Ketiga C# Posted by Unknown on January 13, 2015 Get link Facebook X Pinterest Email Other Apps using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MODUL3_7 { class Program { static void Main(string[] args) { int n; float hasil = 0; int a = 1, b = 2; Console.WriteLine("Hitung (1/2) - (2/3) + (3/4) - (4/5)+...+- N"); Console.WriteLine("============================================"); Console.WriteLine(); Console.Write("jumlah bilangan (min.1) = "); n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); for (int i = 1; i <= n; i++) { float c = (float)a / b; if (i % 2 == 0) hasil -= c; else hasil += c; a += 1; b += 1; } Console.WriteLine("Hasil= " + hasil); Console.ReadKey(); } } } Comments
Comments
Post a Comment