I am trying to sort every element of Array1 in to different categories.
Array1 = 20,25,30,50,80,100
Array2 = 0,25,50,75,100
so every element of Array must be in rage of Array2.
the end result will be:
0 - 25 = 20
25 - 50 = 25,30
50 - 75 = 50
75 - 100 = 80,100
can any one help me with this.
thanks you.
Madhu KRank #1,514 · 1.1K reputationPosted Dec 9, 2010, 9:00 PM EST
int[] arr1 = new int[] { 20, 25, 30, 70,80, 100 };
int[] arr2 = new int[] { 0, 25, 50, 75, 100 };
int a2c = arr2.Count();
for (int i = 0; i <= arr1.Length-2; i++)
{
for (int j = 0; j <= arr2.Length - 2; j++)
{
if (arr1[i] >= arr2[j] && arr1[i] <= arr2[j + 1])
{
MessageBox.Show("array" + arr1[i] + " is in" + arr2[j] + "," + arr2[j + 1]);
}
}
}
Madhu KRank #1,514 · 1.1K reputationPosted Dec 9, 2010, 12:46 AM EST
int[] arr1 = new int[] { 10, 30, 50, 70, 90 };
int[] arr2 = new int[] { 0, 25, 50, 75, 100 };
for (int i = 0; i <= arr2.Length; i++)
{
int s = arr1[i];
if (s > arr2[i] && s < arr2[i+1])
{
MessageBox.Show("array is in" + arr2[i] + "," + arr2[i + 1]);
break;
}
}
Sam HobbsRank #107 · 20.5K reputationPosted Dec 9, 2010, 7:33 AM EST
Kintesh Patel5 reputationPosted Dec 9, 2010, 10:05 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 9, 2010, 11:03 AM EST
Kintesh Patel5 reputationPosted Dec 9, 2010, 11:08 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 9, 2010, 11:45 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 9, 2010, 9:42 PM EST
CrishRank #1,486 · 1.1K reputationPosted Dec 10, 2010, 12:52 AM EST
you can refer following code.It will help you to solve this issue of sorting in to Array values within range of two elements of 2nd Array.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts