printing filtered array content
Demonstrating how to print the filtered array content.
Learning Objectives
- Getting specific data out from an array based on a condition called the filter condition.
Source Code
|
Alternate (?) : |
Run Output
Code Understanding
int ar[]={32,10,19,44,99}; //An array with initialised integer values/
for(int i=0;i<5;i++) //loop to traverse the array terms one by one from index 0
if(ar[i]>30) cout<<ar[i]<<” “;
With in if is the filter condition. This can be simple condition as given here or it can be a complex condition returned from a function. Once the condition is met here we are printing the filtered data.
Notes
- The filter condition can also be returned from a complex condition returned via a selection statement, a series of loops or a function return. Aim is to select specific members of the array which are meeting the criterion.
- The filtered output may stored in a secondary array.
Suggested Filename(s): arr-filt.cpp
sunmitra| Created: 27-Jan-2018 | Updated: 28-Jan-2018|