Answer:
Following is the expression written in "Bash script" (mixture of commands):
^\d{5}(?:[-\s]\d{4})?$
Explanation:
- ^ = For staring string (denotation).
- \d{5} = Matching 5 digits (first five unknown x's)
- (?:…) = Making Group (making group of former 5 digits)
- [-\s] = Match a hyphen or a space
(checking if a hyphen is present?)
- \d{4} = Matching 4 digits (next four unknown x's)
- …? = Pattern before it is optional
- $ = Ending of the string.(denotation)
Answer:
int count =0;
for(int i=0;i<10;i++)
{
if(myArray[i]>=0)
{
count++;
}
}
cout<<"Number of positive integers is "<<count<<endl;
Explanation:
The above written loop is for counting positive integers in the myArray[].
For counting we have taken a count integer initialized with 0.On iterating over the array if the element is greater than or equal to 0 we consider it as positive and increasing the count.At the end printing the count.