+ 6

program to display all alternate element form 2D array in c++

if the array is containing: 12 45 67 33 90 76 21 43 59 the output will be 12 67 90 21 59

29th Aug 2017, 3:22 AM
Kai
Kai - avatar
4 Answers
+ 2
@jay I think C++. @Priyanshu Use this loop in your program: for(int i=0;i<n;i++) { if(i%2==0) { for(int j=0;j<n;j+=2) cout<<mat[i][j]<<" "; } else { for(int j=1;j<n;j+=2) cout<<mat[i][j]<<" "; } } If you wish to start from the element [0,1], just interchange the if and else 's code fragments...
29th Aug 2017, 10:07 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 10
language?
29th Aug 2017, 3:41 AM
jay
jay - avatar
+ 10
it needs to notify you if person updates the question 😯
29th Aug 2017, 10:10 AM
jay
jay - avatar
0
it needs to notify you if person updates the question 😯
19th Aug 2018, 3:10 PM
Ankit Sahu