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 KPosted Dec 10, 2010, 2:00 AM
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]);
}
}
}
CrishPosted Dec 10, 2010, 5:52 AM
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.
Sam HobbsPosted Dec 10, 2010, 2:42 AM
Sam HobbsPosted Dec 9, 2010, 4:45 PM
Kintesh PatelPosted Dec 9, 2010, 4:08 PM
Sam HobbsPosted Dec 9, 2010, 4:03 PM
Kintesh PatelPosted Dec 9, 2010, 3:05 PM
Sam HobbsPosted Dec 9, 2010, 12:33 PM
Madhu KPosted Dec 9, 2010, 5:46 AM
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;
}
}