SlideShare a Scribd company logo
GET 100% MARKS IN
COMPUTER SCIENCE
2-D ARRAY FUNCTION
WRITING QUESTION
EXAM WEIGHTAGE-3/4MARKS
VIDEO 1
FUNCTION HEADER
Void nameof function(int arr[][5], int r,int c)
{
//write your function code here
}
Argument 1 : int arr[][5] for passing 2-d array to
function (first index(row index) no. will be left
blank but it is mandatory to pass the second
index(col index) no. )
Argument 2 : int r to pass the row size of 2d array
Argument 3 : int c to pass the column size of 2d
array
TYPE OF QUESTION
1. To calculate sum of particular elements of a 2d array
2. To print particular elements of a 2 d array
3. To update a 2d array in a particular manner
4. To swap/shift the elements of a 2d array in a particular manner
LOGIC FOR PRINTING A 2D ARRAY
Void PrintArray(int arr[][4],int r, int c)
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<arr[i][j]<<“t”;
}
cout<<“n”;
}
}
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
OUTPUT
LOGIC FOR CALCULATING SUM OF A 2D ARRAY
Void PrintArray(int arr[][4],int r, int c)
{
int sum=0;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
sum=sum+ arr[i][j];
}
}
cout<<“Sum of matrix elements : ”<<sum;
}
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
OUTPUT
Sum of matrix elements : 136
SQUARE MATRIX
00 01 02 03
10 11 12 13
20 21 22 23
30 31 32 33
Square matrix : in which no of row(r) = no of col(c)
1.)Main Diagonal : arr[0][0], arr[1][1], arr[2][2], arr[3][3]
Condition for main diagonal : (i==j)
Off diagonal: arr[0][3], arr[1][2], arr[2][1], arr[3][0]
Condition for off diagonal : (i+j)==r-1 / (i+j)==c-1
Upper triangle : (above main diagonal)
condition (i<=j)
Lower Triangle: (below main diagonal)
condition(i>=j)
Main diagonalOFF Diagonal
1.) Write a function printdiagonal(int arr[][4],int r,int c) to print
diagonals of a 2d array
Void printdiagonal(int arr[][4],int r,int c)
{
cout<<“Diagonal ONE : ”;
for(int i=0;i<r;i++)
{
cout<<arr[i][i]<<“t”;
}
cout<<“nDiagonal TWO :”;
for(int i=0;i<r;i++)
{
Cout<<arr[i][r-1-i];
}
}
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
OUTPUT:
DIAGONAL ONE : 1 6 11 12
DIAGONAL TWO : 4 7 10 13
2.) Write a function printdsum(int arr[][4],int r,int c) to print
sum of diagonals of a 2d array
Void printdsum(int arr[][4],int r,int c)
{
int d1sum=0,d2sum=0;
for(int i=0;i<r;i++)
{
d1sum=d1sum+arr[i][j];
}
for(int i=0;i<r;i++)
{
d2sum=d2sum+arr[i][r-1-i];
}
cout<<“Main Diagonal Sum : ”<<d1sum;
cout<<“nOff Diagonal Sum : ”<<d2sum;
}
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
OUTPUT:
Main Diagonal Sum : 34
Off Diagonal Sum : 34
3.) Write a function printupper(int arr[][5],int r,int c) to print Upper
triangle elements of a 2d array
Void printdiagonal(int arr[][5],int r,int c)
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(i<=j)
cout<<arr[i][j]<<“t”;
else
cout<<“t”;
}
cout<<“n”;
}
}
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
OUTPUT:
1 2 3 4
6 7 8
11 12
16
4.)Write a function printlower(int arr[][5],int r,int c) to print
Upper triangle elements of a 2d array
Void printdiagonal(int arr[][4],int r,int c)
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(i>=j)
cout<<arr[i][j]<<“t”;
else
cout<<“t”;
}
cout<<“n”;
}
}
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
OUTPUT:
1
5 6
9 10 11
13 14 15 16
5.) Write a function printalternate(int arr[][5],int r,int c)
to print Upper triangle elements of a 2d array
Void printdiagonal(int arr[][4],int r,int c)
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(i+j%2==0)
cout<<arr[i][j]<<“t”;
else
cout<<“t”;
}
cout<<“n”;
}
}
Condition :
i+j = even
00 01 02
10 11 12
20 21 22
30 31 32
00 02
11
20 22
31
PRACTICE QUESTION
Q.1) Write a function printuppersum(int arr[][5],int r,int c) to calculate and print sum
Upper triangle elements of a 2d array
Q.2) Write a function printlowersum(int arr[][5],int r,int c) to calculate and print sum of lower triangle
elements of a 2d array
Q.3) Write a function printalternatesum(int arr[][5],int r,int c) to calculate and print sum of alternate
elements of a 2d array
THANKS FOR WATCHING MY VIDEO
EMAIL : theaakashkumar@gmail.com

More Related Content

What's hot

Circular queues
Circular queuesCircular queues
Circular queues
Ssankett Negi
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Ahmed Khateeb
 
Permute
PermutePermute
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
Rumman Ansari
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
Rajendran
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
Angshuman Saha
 
Removal Of Recursion
Removal Of RecursionRemoval Of Recursion
Removal Of Recursion
Richa Sharma
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
JeeSa Sultana
 
Permute
PermutePermute
Matlab integration
Matlab integrationMatlab integration
Matlab integration
pramodkumar1804
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
Kulachi Hansraj Model School Ashok Vihar
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelization
Albert DeFusco
 
Stack Data Structure V1.0
Stack Data Structure V1.0Stack Data Structure V1.0
Stack Data Structure V1.0
Zidny Nafan
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 

What's hot (19)

Circular queues
Circular queuesCircular queues
Circular queues
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
Permute
PermutePermute
Permute
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
Removal Of Recursion
Removal Of RecursionRemoval Of Recursion
Removal Of Recursion
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
Permute
PermutePermute
Permute
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Array notes
Array notesArray notes
Array notes
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelization
 
Functions
FunctionsFunctions
Functions
 
Stack Data Structure V1.0
Stack Data Structure V1.0Stack Data Structure V1.0
Stack Data Structure V1.0
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
 

Similar to 2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS

2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 
#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdf#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdf
brijmote
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
dhavalbl38
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
Aram Jamal
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
Dr. Md. Shohel Sayeed
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
Yung-Yu Chen
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
Aman Deep
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
Aman Deep
 
Function recap
Function recapFunction recap
Function recapalish sha
 
Function recap
Function recapFunction recap
Function recapalish sha
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
tarifarmarie
 
Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
guest9006ab
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
ebinazer1
 

Similar to 2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS (20)

2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
Arrays
ArraysArrays
Arrays
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdf#include iostream using namespace std; void InsertionSort(int .pdf
#include iostream using namespace std; void InsertionSort(int .pdf
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
Function recap
Function recapFunction recap
Function recap
 
Function recap
Function recapFunction recap
Function recap
 
Managing console
Managing consoleManaging console
Managing console
 
Vcs16
Vcs16Vcs16
Vcs16
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
 
Qno 3 (a)
Qno 3 (a)Qno 3 (a)
Qno 3 (a)
 
Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Advanced C - Part 3
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 

More from AAKASH KUMAR

NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
AAKASH KUMAR
 
Inheritance question
Inheritance questionInheritance question
Inheritance question
AAKASH KUMAR
 
Header file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12THHeader file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12TH
AAKASH KUMAR
 
Constructor & destructor based question- cbse cs class 12th
Constructor & destructor based question-  cbse cs class 12thConstructor & destructor based question-  cbse cs class 12th
Constructor & destructor based question- cbse cs class 12th
AAKASH KUMAR
 
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAMCHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
AAKASH KUMAR
 
Practical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12thPractical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12th
AAKASH KUMAR
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
AAKASH KUMAR
 
Ms word Part 2
Ms  word Part 2Ms  word Part 2
Ms word Part 2
AAKASH KUMAR
 
Ms word Part 1
Ms  word Part 1Ms  word Part 1
Ms word Part 1
AAKASH KUMAR
 
Power point2007instruction
Power point2007instructionPower point2007instruction
Power point2007instruction
AAKASH KUMAR
 
Html introduction Part-2
Html introduction Part-2Html introduction Part-2
Html introduction Part-2
AAKASH KUMAR
 
Html Slide Part-1
Html Slide Part-1Html Slide Part-1
Html Slide Part-1
AAKASH KUMAR
 
Evolution / history of Computer
Evolution / history of ComputerEvolution / history of Computer
Evolution / history of Computer
AAKASH KUMAR
 
computer system
computer system computer system
computer system
AAKASH KUMAR
 
Array within a class
Array within a classArray within a class
Array within a class
AAKASH KUMAR
 
Input Output Devices and Memory Unit
Input Output Devices and Memory UnitInput Output Devices and Memory Unit
Input Output Devices and Memory Unit
AAKASH KUMAR
 
C++ programming Unit 5 flow of control
C++ programming Unit 5 flow of controlC++ programming Unit 5 flow of control
C++ programming Unit 5 flow of control
AAKASH KUMAR
 
c++ programming Unit 4 operators
c++ programming Unit 4 operatorsc++ programming Unit 4 operators
c++ programming Unit 4 operators
AAKASH KUMAR
 
c++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data typesc++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data types
AAKASH KUMAR
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ program
AAKASH KUMAR
 

More from AAKASH KUMAR (20)

NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
 
Inheritance question
Inheritance questionInheritance question
Inheritance question
 
Header file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12THHeader file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12TH
 
Constructor & destructor based question- cbse cs class 12th
Constructor & destructor based question-  cbse cs class 12thConstructor & destructor based question-  cbse cs class 12th
Constructor & destructor based question- cbse cs class 12th
 
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAMCHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
 
Practical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12thPractical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12th
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
 
Ms word Part 2
Ms  word Part 2Ms  word Part 2
Ms word Part 2
 
Ms word Part 1
Ms  word Part 1Ms  word Part 1
Ms word Part 1
 
Power point2007instruction
Power point2007instructionPower point2007instruction
Power point2007instruction
 
Html introduction Part-2
Html introduction Part-2Html introduction Part-2
Html introduction Part-2
 
Html Slide Part-1
Html Slide Part-1Html Slide Part-1
Html Slide Part-1
 
Evolution / history of Computer
Evolution / history of ComputerEvolution / history of Computer
Evolution / history of Computer
 
computer system
computer system computer system
computer system
 
Array within a class
Array within a classArray within a class
Array within a class
 
Input Output Devices and Memory Unit
Input Output Devices and Memory UnitInput Output Devices and Memory Unit
Input Output Devices and Memory Unit
 
C++ programming Unit 5 flow of control
C++ programming Unit 5 flow of controlC++ programming Unit 5 flow of control
C++ programming Unit 5 flow of control
 
c++ programming Unit 4 operators
c++ programming Unit 4 operatorsc++ programming Unit 4 operators
c++ programming Unit 4 operators
 
c++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data typesc++ programming Unit 3 variables,data types
c++ programming Unit 3 variables,data types
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ program
 

Recently uploaded

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS

  • 1.
  • 2. GET 100% MARKS IN COMPUTER SCIENCE 2-D ARRAY FUNCTION WRITING QUESTION EXAM WEIGHTAGE-3/4MARKS VIDEO 1
  • 3. FUNCTION HEADER Void nameof function(int arr[][5], int r,int c) { //write your function code here } Argument 1 : int arr[][5] for passing 2-d array to function (first index(row index) no. will be left blank but it is mandatory to pass the second index(col index) no. ) Argument 2 : int r to pass the row size of 2d array Argument 3 : int c to pass the column size of 2d array
  • 4. TYPE OF QUESTION 1. To calculate sum of particular elements of a 2d array 2. To print particular elements of a 2 d array 3. To update a 2d array in a particular manner 4. To swap/shift the elements of a 2d array in a particular manner
  • 5. LOGIC FOR PRINTING A 2D ARRAY Void PrintArray(int arr[][4],int r, int c) { for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { cout<<arr[i][j]<<“t”; } cout<<“n”; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 OUTPUT
  • 6. LOGIC FOR CALCULATING SUM OF A 2D ARRAY Void PrintArray(int arr[][4],int r, int c) { int sum=0; for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { sum=sum+ arr[i][j]; } } cout<<“Sum of matrix elements : ”<<sum; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 OUTPUT Sum of matrix elements : 136
  • 7. SQUARE MATRIX 00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33 Square matrix : in which no of row(r) = no of col(c) 1.)Main Diagonal : arr[0][0], arr[1][1], arr[2][2], arr[3][3] Condition for main diagonal : (i==j) Off diagonal: arr[0][3], arr[1][2], arr[2][1], arr[3][0] Condition for off diagonal : (i+j)==r-1 / (i+j)==c-1 Upper triangle : (above main diagonal) condition (i<=j) Lower Triangle: (below main diagonal) condition(i>=j) Main diagonalOFF Diagonal
  • 8. 1.) Write a function printdiagonal(int arr[][4],int r,int c) to print diagonals of a 2d array Void printdiagonal(int arr[][4],int r,int c) { cout<<“Diagonal ONE : ”; for(int i=0;i<r;i++) { cout<<arr[i][i]<<“t”; } cout<<“nDiagonal TWO :”; for(int i=0;i<r;i++) { Cout<<arr[i][r-1-i]; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 OUTPUT: DIAGONAL ONE : 1 6 11 12 DIAGONAL TWO : 4 7 10 13
  • 9. 2.) Write a function printdsum(int arr[][4],int r,int c) to print sum of diagonals of a 2d array Void printdsum(int arr[][4],int r,int c) { int d1sum=0,d2sum=0; for(int i=0;i<r;i++) { d1sum=d1sum+arr[i][j]; } for(int i=0;i<r;i++) { d2sum=d2sum+arr[i][r-1-i]; } cout<<“Main Diagonal Sum : ”<<d1sum; cout<<“nOff Diagonal Sum : ”<<d2sum; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 OUTPUT: Main Diagonal Sum : 34 Off Diagonal Sum : 34
  • 10. 3.) Write a function printupper(int arr[][5],int r,int c) to print Upper triangle elements of a 2d array Void printdiagonal(int arr[][5],int r,int c) { for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { if(i<=j) cout<<arr[i][j]<<“t”; else cout<<“t”; } cout<<“n”; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 OUTPUT: 1 2 3 4 6 7 8 11 12 16
  • 11. 4.)Write a function printlower(int arr[][5],int r,int c) to print Upper triangle elements of a 2d array Void printdiagonal(int arr[][4],int r,int c) { for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { if(i>=j) cout<<arr[i][j]<<“t”; else cout<<“t”; } cout<<“n”; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 OUTPUT: 1 5 6 9 10 11 13 14 15 16
  • 12. 5.) Write a function printalternate(int arr[][5],int r,int c) to print Upper triangle elements of a 2d array Void printdiagonal(int arr[][4],int r,int c) { for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { if(i+j%2==0) cout<<arr[i][j]<<“t”; else cout<<“t”; } cout<<“n”; } } Condition : i+j = even 00 01 02 10 11 12 20 21 22 30 31 32 00 02 11 20 22 31
  • 13. PRACTICE QUESTION Q.1) Write a function printuppersum(int arr[][5],int r,int c) to calculate and print sum Upper triangle elements of a 2d array Q.2) Write a function printlowersum(int arr[][5],int r,int c) to calculate and print sum of lower triangle elements of a 2d array Q.3) Write a function printalternatesum(int arr[][5],int r,int c) to calculate and print sum of alternate elements of a 2d array
  • 14. THANKS FOR WATCHING MY VIDEO EMAIL : theaakashkumar@gmail.com