-
16-10-2010, 03:02 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Tìm ước số chung của 2 số trong lập trình C# đây
Mã:namespace ConsoleApplication{ class program { static void Main(string[] args) { tinh bt=new tinh(); bt.nhap(); Console.writeLine("uoc chung lon nhat cua 2 so la {0}",bt.tinh_bt()); Console.ReadLine(); } } class tinh { private int a,b; public void nhap() { Console.Write("nhap a:"); a=Convert.ToInt32(Console.ReadLine()); Console.write("nhap b:"); b=Convert.ToInt32(Console.ReadLine()); } public int tinh_bt() { while(a!=b) { if(a>b) a=a-b; else b=b-a; } return a; } }}
View more random threads:
- Hướng dẫn tách dữ liệu từ ListBox sang TextBox
- 21 Important FAQ questions for WPF and SilverLight
- cách dùng post jquery data jones MVC3
- Chế độ tô vẽ và vẽ mượt mà (antialiashing) trong lập trình C#
- Tự mản Nunber
- Tìm hiểu về Anonymous method trong lập trình C#
- Phân trang trong winform - Paging in winform. Hướng dẫn chi tiết + Source code
- Xử lý Bitmap, Color trong lập trình C#
- Hook keyboard và mouse hook trong c# không cần code
- Xử lý kích thước và vị trí của Form trong lập trình C#
-
29-10-2010, 05:56 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Kia là tìm ước số chung lớn nhất.
dưới đây là đọn code tìm tất cả ước số chung
----------------------------------------------------------------------------------------------------
Mã:using System;using System.Collections.Generic; namespace Mathematics{ class Program { static void Main(string[ ] args) { TimUSC bt = new TimUSC(); List<int> lisReturn = new List<int>(); lisReturn = bt.timUSC( lisReturn ); Console.WriteLine( "USC là: " ); foreach (int i in lisReturn) { Console.Write( " {0}", i ); } Console.ReadLine(); } class TimUSC { private int inta, intb; public void nhap() { Console.Write( "nhap a:" ); inta = Convert.ToInt32( Console.ReadLine() ); Console.Write( "nhap b:" ); intb = Convert.ToInt32( Console.ReadLine() ); } public List<int> timUSC(List<int> lisReturn) { nhap(); int intc = inta < intb ? intb : inta; for (int i = 1; i <= intc; i++) { if (( inta % i == 0 ) && ( intb % i == 0 )) lisReturn.Add( i ); } return lisReturn; } } }}
Trứng rung điều khiển từ xa Vibrator Spark Of Love Sản phẩm trứng rung bluetooth có điều khiển từ xa này được thiết kế với tông màu Rose Gold viền kim khí trải qua. kích tấc 7,4cm x 3,5cm giúp trứng...
TOP 3 trùy rung điều khiển từ xa...