Programmings Based On Array And String Functions To Find How Many Numbers Of Positive, Negative And Zero Numbers Present In The Array $arr=array(-1,-2,-3,-4,0,0,1,2,3,4)
Programmings Based On Array And String Functions To Find How Many Numbers Of Positive, Negative And Zero Numbers Present In The Array $arr=array(-1,-2,-3,-4,0,0,1,2,3,4)
Q1. Find how many numbers of Positive, Negative, 0 numbers present in this array.
$arr=array(-1,-2,-3,-4,0,0,1,2,3,4)
Ans: Coding =>
Output Of The Coding =>
Explanation Of The Coding =>
In $arr=array(-1,-2,-3,-4,0,0,1,2,3,4), -1 is in the 0 position, -2 is in the 1st position, -3 is in the 2nd position, -4 is in the 3rd position, 0 is in the 4th position, 0 is in the 5th position, 1 is in the 6th position, 2 is in the 7th position, 3 is in the 8th position and 4 is in the 9th position.
Then $len=count($arr) where $len=count(array(-1)) i.e. $len=count(0) where for($i=0;0<-1;$i++) and as 0 is not less than -1 so it will go into the elseif part and if in elseif part $arr[0]<0 i.e. if in elseif part -1<0 and as this condition satisfies -1<0 so it will print $nn++ i.e. it will print -1 as the negative number $nn++.
And again now $i will increase by 1 as it is $i++ so now $i will be 0+1 i.e. 1 and $len=count(array(-2)) i.e. $len=count(1) again now it will check the for loop $i=1;1<-2;$i++) and as 1 is not less than -2 so it will go into the elseif part and if in elseif part $arr[1]<0 i.e. if in elseif part -2<0 and as this condition satisfies -2<0 so it will print $nn++ i.e. it will print -2 as the negative number $nn++.
So in this way the loop will continue to rotate.
Comments
Post a Comment