代码 如何在一个数组里面找到两个数,使它们之和为参数所指定的数?比如{1,2,3,4,5},指定6,得到1,5 和 2,4 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int num = 6; int num1 = 0; int num2 = 0; string str = ""; int[] arr = { 1, 2, 3, 4, 5 }; int len = arr.Length; for (int i = 0; i < len; i++) { num1 = arr[i]; for (int j =(i+1); j < len;j++ ) { num2 = arr[j]; if ((num1 + num2) == num) { str += num1.ToString() + "," + num2.ToString() + " "; } } } Response.Write("结果为:"+str); public static void Test() { Int32[] paras = { 1, 2, 3, 4, 5 }; List<Int32> temp = new List<Int32>(paras); temp.Sort(); Int32 i = 6; var v = from p1 in temp from p2 in temp where p1 + p2 == i select new { p1, p2 }; foreach (var p in v) { Int32 p1 = p.p1; Int32 p2 = p.p2; if (p1 <= p2) { if (p1 != p2 || (p1 == p2 && (temp.FindAll((pa) => { if (pa == p1) return true; else return false; }).Count<Int32>() > 1))) { Console.WriteLine(p1 + " " + p2); } } } } int[] a={1,2,3,4,5,6}; int Number = 6; ArrayList NumberList = new ArrayList(); for(int i=0;i<a.Length;i++) { for (int j = i + 1; j < a.Length;j++ ) { if (a[i] + a[j] == Number) { NumberList.Add(a[i].ToString() + "," + a[j].ToString()); } } } 重启iis 需要多少时间 为什么我保存的网页都成了htm文件? 庆国庆、迎中秋;【请教】关于高并发 aspx页面中动态调用脚本问题~急! DataList无法显示间隔项?急 哪位大哥能帮我解决一下ado.net中的事务的问题.谢谢! 求助!谁有asp.net参考手册的电子书, 如何用框体检查的errormessage控制label控件的text的值? 为什么访问数据库背拒绝 在运行程序时出现以下错误,是什么问题! 参数问题 在主页上摆很多ImageButton 然后另外做一个页面。通过将点击不同的ImageButton 将参数传给那个页面而显示不同的内容?
int num = 6;
int num1 = 0;
int num2 = 0;
string str = "";
int[] arr = { 1, 2, 3, 4, 5 };
int len = arr.Length;
for (int i = 0; i < len; i++)
{
num1 = arr[i];
for (int j =(i+1); j < len;j++ )
{
num2 = arr[j];
if ((num1 + num2) == num)
{
str += num1.ToString() + "," + num2.ToString() + " ";
}
}
}
Response.Write("结果为:"+str);
public static void Test()
{
Int32[] paras = { 1, 2, 3, 4, 5 };
List<Int32> temp = new List<Int32>(paras);
temp.Sort();
Int32 i = 6;
var v = from p1 in temp from p2 in temp where p1 + p2 == i select new { p1, p2 };
foreach (var p in v)
{
Int32 p1 = p.p1;
Int32 p2 = p.p2;
if (p1 <= p2)
{
if (p1 != p2 || (p1 == p2 && (temp.FindAll((pa) => { if (pa == p1) return true; else return false; }).Count<Int32>() > 1)))
{
Console.WriteLine(p1 + " " + p2);
}
}
}
}
int[] a={1,2,3,4,5,6};
int Number = 6;
ArrayList NumberList = new ArrayList();
for(int i=0;i<a.Length;i++)
{
for (int j = i + 1; j < a.Length;j++ )
{
if (a[i] + a[j] == Number)
{
NumberList.Add(a[i].ToString() + "," + a[j].ToString());
}
}
}