minhlap Admin - Quản trị viên
Tổng số bài gửi : 129 Points : 374 Reputation : 5 Join date : 22/07/2009 Age : 34 Đến từ : TP Hồ Chí Minh
| Tiêu đề: Một số bài tập của mình bài 1 mảng số nguyên, minh họa hàm random Tue Sep 01, 2009 3:09 pm | |
| Đây là một số bài tập mình làm được các bạn có thể tham khảo hay đánh giá Bài 1: mảng số nguyên - Code:
-
using System; using System.Collections.Generic; using System.Linq; using System.Text;
class Mang { int[] a; public Mang() { a = new int[5]; } public void nhap() { string s; Console.WriteLine("Tao mang thu cong "); for (int i = 0; i < 5; i++) { Console.Write("Nhap a[{0}] :",i); s = Console.ReadLine(); a[i] = Convert.ToInt32(s); } } public void nhaprand() { Random s = new Random(); int x; Console.WriteLine("Tao mang ngau nhien"); for (int i = 0; i < 5; i++) { x = s.Next()%100; a[i] = x; } } public void xuat() { Console.WriteLine("Mang vua nhap la :"); for (int i = 0; i < 5; i++) { Console.WriteLine("Phan tu thu a[i] :{0}",a[i]); } } static void Main(string[] args) { Mang a = new Mang(); int ch; bool cont = true; string s; Console.WriteLine("---------Mang mot chieu---------"); Console.WriteLine("1/ Tao mang ngau nhien"); Console.WriteLine("2/ Nhap mang thu cong"); Console.WriteLine("3/ Thoat"); while (cont==true) { Console.Write("----Chon :"); s = Console.ReadLine(); ch = Convert.ToInt32(s); switch (ch) { case 1: a.nhaprand(); a.xuat(); break; case 2: a.nhap(); a.xuat(); break; case 3: Console.WriteLine("Chao tam biet - hen gap lai"); cont = false; break; } }; } } | |
|