Operasi Himpunan Dengan Array C# Posted by Unknown on January 14, 2015 Get link Facebook X Pinterest Email Other Apps Dengan keterangan program : - Input berupa : Jumlah Bilangan Himpunan A dan B, serta Nilai dari setiap Himpunan. - Setiap nilai dari himpunan yang diinput dan dihasilkan akan disimpan ke dalam Array. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MODUL5_5 { class Program { static void Main(string[] args) { int a, b; int[] A = new int[0]; int[] B = new int[0]; int[] gabung = new int[0]; Console.Write("Jumlah Bilangan Himpunan A = "); a = Convert.ToInt32(Console.ReadLine()); Console.Write("Jumlah Bilangan Himpunan B = "); b= Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("Input Himpunan A :"); for (int i = 0; i < a; i++) { Array.Resize(ref A, A.Length + 1); Console.Write("\t Nilai A-{0} = ", i + 1); A[A.GetUpperBound(0)] = Convert.ToInt32(Console.ReadLine()); } Console.WriteLine(); Console.WriteLine("Input Himpunan B:"); for (int i = 0; i < b; i++) { Array.Resize(ref B, B.Length + 1); Console.Write("\t Nilai B-{0} = ", i + 1); B[B.GetUpperBound(0)] = Convert.ToInt32(Console.ReadLine()); } Console.WriteLine(); Console.Write("Himpunan A ={"); for (int i = 0; i < a; i++) { Console.Write(A[i]+" "); } Console.Write("}"); Console.WriteLine(); Console.Write("Himpunan B ={"); for (int i = 0; i < b; i++) { Console.Write(B[i] + " "); } Console.Write("}"); Console.WriteLine(); for (int i = 0; i < a + b; i++) { Array.Resize(ref gabung, gabung.Length + 1); if (i < a) { gabung[i] = A[i]; } else { gabung[i] = B[i - a]; } } Array.Sort(gabung); Console.Write("Himpunan A dan Gabung B = {"); for (int i = 0; i < gabung.Length;i++ ) { if (i == 0) { Console.Write(gabung[i] + " "); } else if (gabung[i] != gabung[i - 1]) { Console.Write(gabung[i] + " "); } else { Console.Write(""); } } Console.Write("}"); Console.ReadKey(); } } } Comments Robert Butar butar9 November 2016 at 09:39makasi yah.. sanggt mmbantuReplyDeleteRepliesReplyAdd commentLoad more... Post a Comment
makasi yah.. sanggt mmbantu
ReplyDelete