Counts different propertied elements of an array

FlamingClaw 0 Tallied Votes 174 Views Share

Counts that how many propertied elements are in the array
example:negative numbers
By FlamingClaw

{
Question

Counts that how many propertied elements are in the array
example:negative numbers

The rule:
s:=0;
Loop i:=1..N
 If T[i]<0 Then s:=s+1;
End of Loop;
Out: s;
}
Program Solution01;
Const n = 5;
      m = -10;
Var  s,i:Integer;
       T:Array[m..n]Of Integer;
Begin {main}
   WriteLn('First run:');
   {create random numbers and fill the array with them}
   Randomize;{it is important!}
   For i:=m To n Do Begin
      T[i]:=Random(m)+n;  {-10..5}
      Write(T[i]:3);
   End;
   WriteLn;
   {analizing}
   s:=0;
   For i:=m To n Do Begin
      If (T[i] < 0) Then s:=s+1;
   End;
   {write the number of negative numbers}
   Write('The number of negative numbers: ',s);
   ReadLn;
End.

{
-= Note By FlamingClaw =-

All programs created by me are written and tested
in Dev Pascal and/or Turbo Pascal 7.0
Of course working!

-= Created By FlamingClaw =-
-=2009.04.05=-
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.