an array is filter array when it meets the following conditions:
- if 9 exists in the list 13 must also exist
- if 7 exists in the list then 11 must not exist
solution
int[] a = {7 , 72, 6, 13, 9 };
int i, k = 0, l = 0, m = 0, n = 0;
for (i = 0; i < a.Length; i++)
{
if (a[i] == 9)
{
k = 1;
}
}
for (i = 0; i < a.Length; i++)
{
if (a[i] == 13)
{
l = 1;
}
}
for (i = 0; i < a.Length; i++)
{
if (a[i] == 7)
{
m = 1;
}
}
for (i = 0; i < a.Length; i++)
{
if (a[i] == 11)
{
n= 1;
}
}
if ((k == 1 && l == 1) && (m == 1 && n == 1))
{
Console.WriteLine("is not filter array");
}
else if (k == 1 && l!= 1)
{
Console.WriteLine("is not filter array");
}
else if (m ==1 && n==1)
{
Console.WriteLine("is not filter array ");
}
else
Console.WriteLine("is filter array");
Console.WriteLine("the element of an array is:");
for (i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
As i think this code is surely work for if you need to test an array.
reta seboka ambo universtity woliso campuse department of information TECH.!!