printing filtered array content – CSKC
Sign In

Search

Code Learning #CPP#3095    siteicon   siteicon  

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

TC++ #3095

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Alternate (?) :

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



Share

Created: 27-Jan-2018 23:22 | Updated: 28-Jan-2018 00:31|