Menghitung Deret barisan Bilangan Kedua 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_6 { class Program { static void Main(string[] args) { int hasil = 0; int temp = 0; int n; int b = 0, a = 2; Console.WriteLine("Hitung 2-4+6-8+...+- 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++) { if (i % 2 != 0) { b += a; temp += b; hasil = temp; } else { b += a; temp -= b; hasil = temp; } } Console.WriteLine("Hasil= " + hasil); Console.ReadKey(); } } } Comments
Comments
Post a Comment