hi im preparing for an exam and i am new to c# i am having problem with a question that i have
what i am having problem is that i need to find out how many times the number greater than or less than one appears in the array for example
if i have an array {1,1,1,2,3,-18,45,1} here numbers that are greater than or less than one appears just once
another example if i have an array {1,1,1,2,3,-18,45,1,0} here numbers that are greater than or less than one appears twice that is at the second last there is one and after that there is zero
yet another example {1,1,2,3,1,-18,26,1} here numbers that are greater than or less than one appears twice one set is {2,3} thats once and another set is {-18,26} so thats twice
so far ive been able to loop the array but im stuck .. how to do this
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine(isOneBalanced(new int[] { 1, 1, 1, 2, -18, 45, 1 }));
}
static int isOneBalanced(int[] a)
{
foreach(int a1 in a)
{
}
return 0;
}
}
how to do this can anybody help me