求约束------------------------ do while循环 算法思想
前段代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h2>求2到200之间任意一个数的约数</h2> <br/> 输入任意一个数字:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br/> <asp:Button ID="Button" runat="server" Text="取余" onclick="Button_Click" /> <br/> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </div> </form> </body> </html>
后端代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button_Click(object sender, EventArgs e) { int yueshu; int i=1; string temp = ""; yueshu = int.Parse(TextBox1.Text); do { if (yueshu % i == 0) { temp += " "+i; } i++; } while (i<=yueshu); Label1.Text = temp; } }