Function to display middle column of 2D Array – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-CBSE12A-2016-03D #CPP#5668    siteicon   siteicon  

Problem Statement - Function to display middle column of 2D Array

Write definition for a function DISPMID(int A[][5],int R,int C) in C++ to display the elements of middle row and middle column from a two dimensional array A having R number of rows and C number of columns.
For example, if the content of array is as follows:

215 912 516 401 515
103 901 921 802 601
285 209 609 360 172

The function should display the following as output
103 901 921 802 601
516 921 609

Solution

TC++ #5668

void DISPMID(int A[][5],int R,int C)
{
  for (int J=0;J<C;J++)
  cout<<A[R/2][J]<< “ “;
  cout<<endl;
  for (int I=0;I<R;I++)
  cout<<A[I][C/2]<< “ “;
}
OR
void DISPMID(int A[][5],int R,int C)
{
if(R%2!=0)
{
  for (int J=0;J<C;J++)
  cout<<A[R/2][J]<< “ “;
}
  else
  cout<<”No Middle Row”;
  cout<<endl;
  if(C%2!=0)
{
  for (int I=0;I<R;I++)
  cout<<A[I][C/2]<< “ “;
}
  else
  cout<<”No Middle Column”;
}

OR
Any other correct equivalent function definition


Share

CSKC| Created: 1-Jan-2019 | Updated: 10-Oct-2019|CBSE12A-2016






×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back