SlideShare a Scribd company logo
C++ : ARRAY WITH EXAMPLES 
SUMMATION OF TWO MATRIXES 
#include <iostream> 
using namespace std; 
int main() 
{ 
int m,n,c,d, first[10][10], second[10][10], sum[10][10]; 
cout << "Enter the number of rows and columns of matrix" << endl; 
cin >> m>> n; 
cout << "Enter the elements of first matrix n"; 
for( c=0; c<m ; c++) 
for(d=0; d<n ; d++) 
cin >> first [c][d]; 
cout << "Enter the elements of second matrix n"; 
for(c=0; c<m; c++) 
for(d=0; d<n; d++) 
cin >> second[c][d]; 
for (c=0;c<m;c++) 
for(d=0;d<n;d++) 
sum[c][d]= first[c][d] + second[c][d];
cout << "The summation of entered matrixes :- n"; 
for(c=0; c<m; c++) 
{ 
for(d=0; d<n; d++) 
cout << sum[c][d] << "t"; 
cout << endl; 
} 
return 0; 
} 
//Output : 
Enter the number of rows and columns of matrix 
3 3 
Enter the elements of first matrix 
1 2 3 
4 5 6 
7 8 9 
Enter the elements of second matrix 
1 2 3 
4 5 6 
7 8 9 
The summation of entered matrixes :- 
2 4 6 
8 10 12 
14 16 18
DIFFERENCE OF TWO MATRIXES 
#include <iostream> 
using namespace std; 
int main() 
{ 
int m,n,c,d, first[10][10], second[10][10], sum[10][10]; 
cout << "Enter the number of rows and columns of matrix" << endl; 
cin >> m>> n; 
cout << "Enter the elements of first matrix n"; 
for( c=0; c<m ; c++) 
for(d=0; d<n ; d++) 
cin >> first [c][d]; 
cout << "Enter the elements of second matrix n"; 
for(c=0; c<m; c++) 
for(d=0; d<n; d++) 
cin >> second[c][d]; 
for (c=0;c<m;c++) 
for(d=0;d<n;d++) 
sum[c][d]= first[c][d] - second[c][d]; 
cout << "The summation of entered matrixes :- n"; 
for(c=0; c<m; c++) 
{
for(d=0; d<n; d++) 
cout << sum[c][d] << "t"; 
cout << endl; 
} 
return 0; 
} 
//Output: 
Enter the number of rows and columns of matrix 
3 3 
Enter the elements of first matrix 
7 8 9 
4 5 6 
1 2 3 
Enter the elements of second matrix 
1 2 3 
4 5 6 
7 8 9 
The summation of entered matrixes :- 
6 6 6 
0 0 0 
-6 -6 -6
TRANSPOSE OF A MATRIX 
#include <iostream> 
using namespace std; 
int main() 
{ 
int c,d, matrix[3][3],transpose_matrix[3][3]; 
cout <<"Enter the elements of 3x3 matrix n"; 
for( c=0; c<3 ; c++) 
for(d=0; d<3 ; d++) 
cin >> matrix [c][d]; 
for (c=0;c<3;c++) 
for(d=0;d<3;d++) 
transpose_matrix[c][d]= matrix[d][c]; 
cout << "The transpose of the given 3x3 matrix :- n"; 
for(c=0; c<3; c++) 
{ 
for(d=0; d<3; d++) 
cout << transpose_matrix[c][d] << "t"; 
cout << endl; 
} 
return 0; 
}
//Output: 
Enter the elements of 3x3 matrix 
1 2 3 
4 5 6 
7 8 9 
The transpose of the given 3x3 matrix :- 
1 4 7 
2 5 8 
3 6 9 
// Alternative way to find transpose of a matrix: 
#include <iostream> 
using namespace std; 
int main() 
{ 
int m,n,c,d, matrix[10][10],transpose_matrix[10][10]; 
cout << "Enter the number of rows and columns of matrix" << endl; 
cin >> m>> n; 
cout << "Enter the elements of matrix n"; 
for( c=0; c<m ; c++) 
for(d=0; d<n ; d++) 
cin >> matrix [c][d]; 
for (c=0;c<m;c++) 
for(d=0;d<n;d++)
transpose_matrix[c][d]= matrix[d][c]; 
cout << "The transpose of the entered matrixes :- n"; 
for(c=0; c<m; c++) 
{ 
for(d=0; d<n; d++) 
cout << transpose_matrix[c][d] << "t"; 
cout << endl; 
} 
return 0; 
} 
// Output: 
Enter the number of rows and columns of matrix 
5 5 
Enter the elements of matrix 
1 2 3 4 5 
6 7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 
21 22 23 24 25 
The transpose of the entered matrixes :- 
1 6 11 16 21 
2 7 12 17 22 
3 8 13 18 23 
4 9 14 19 24 
5 10 15 20 25
MULTIPLICATION OF TWO MATRIXES (2X2 DIMENSION ONLY) 
#include <iostream> 
using namespace std; 
int main() 
{ 
int m,n,c,d, first[2][2], second[2][2], mult[2][2]; 
cout << "Enter the number of rows and columns of matrix" << endl; 
cin >> m>> n; 
cout << "Enter the elements of first matrix n"; 
for( c=0; c<m ; c++) 
for(d=0; d<n ; d++) 
cin >> first [c][d]; 
cout << "Enter the elements of second matrix n"; 
for(c=0; c<m; c++) 
for(d=0; d<n; d++) 
cin >> second[c][d]; 
for (c=0;c<m;c++) 
for(d=0;d<n;d++) 
mult[c][d]= first[c][0] * second[0][d] + first[c][1] * second[1][d]; 
cout << "Multiplication of entered matrixes :- n";
for(c=0; c<m; c++) 
{ 
for(d=0; d<n; d++) 
cout << mult[c][d] << "t"; 
cout << endl; 
} 
return 0; 
} 
//Output : 
Enter the number of rows and columns of matrix 
2 2 
Enter the elements of first matrix 
1 2 
3 4 
Enter the elements of second matrix 
1 2 
3 4 
Multiplication of entered matrixes :- 
7 10 
15 22
INVERSE OF A MATRIX (2x2 DIMENSION ONLY) 
#include <iostream> 
using namespace std; 
int main() 
{ 
int c,d, determinant, matrix[2][2], inv[2][2]; 
cout << "Enter the elements of 2x2 matrix n"; 
for( c=0; c<2 ; c++) 
for(d=0; d<2 ; d++) 
cin >> matrix [c][d]; 
determinant= matrix[0][0] * matrix[1][1] - matrix[0][1]*matrix[1][0]; 
for (c=0; c<2; c++) 
for(d=0; d<2; d++) 
{ if ( c==0 && d==0) 
inv[c][d]= matrix[1][1]; 
else if (c==1 && d==1) 
inv[c][d]= matrix[0][0]; 
else 
inv[c][d]= - matrix[c][d]; 
}
cout << "Inverse of entered matrixes :- n"; 
for(c=0; c<2; c++) 
{ 
for(d=0; d<2; d++) 
cout << (float) inv[c][d]/determinant << "t"; 
cout << endl; 
} 
return 0; 
} 
//Output: 
Enter the elements of 2x2 matrix 
1 2 
3 4 
Inverse of entered matrixes :- 
-2 1 
1.5 -0.5

More Related Content

What's hot

Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded Types
Philip Schwarz
 
C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
Arrays
ArraysArrays
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
Chris Ohk
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
Container adapters
Container adaptersContainer adapters
Container adapters
mohamed sikander
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
Saurabh Singh
 
Function recap
Function recapFunction recap
Function recapalish sha
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 
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
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
Luca Molteni
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
Chris Ohk
 
An Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using HaskellAn Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using Haskell
Michel Rijnders
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
Germán Küber
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
faradjpour
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its functionFrankie Jones
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
Chris Ohk
 

What's hot (20)

Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded Types
 
C tech questions
C tech questionsC tech questions
C tech questions
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
Container adapters
Container adaptersContainer adapters
Container adapters
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Function recap
Function recapFunction recap
Function recap
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
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
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 
An Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using HaskellAn Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using Haskell
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 

Viewers also liked

Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
Awais Alam
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
Arrays
ArraysArrays
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
George Erfesoglou
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array PointerTareq Hasan
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
k v
 
Cisco Industry template - 4x3 dark
Cisco Industry template - 4x3 darkCisco Industry template - 4x3 dark
Cisco Industry template - 4x3 darkKVEDesign
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
akmalfahmi
 

Viewers also liked (20)

Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Array in c++
Array in c++Array in c++
Array in c++
 
Arrays
ArraysArrays
Arrays
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Array in C
Array in CArray in C
Array in C
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
functions of C++
functions of C++functions of C++
functions of C++
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Cisco Industry template - 4x3 dark
Cisco Industry template - 4x3 darkCisco Industry template - 4x3 dark
Cisco Industry template - 4x3 dark
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
 

Similar to C++ ARRAY WITH EXAMPLES

C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
Farhan Ab Rahman
 
2D array
2D array2D array
2D array
A. S. M. Shafi
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]
Kanis Fatema Shanta
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
Dr. Md. Shohel Sayeed
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
Mouna Guru
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
Cpp programs
Cpp programsCpp programs
Cpp programs
harman kaur
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
Aroosa Rajput
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
PVS-Studio LLC
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
Pranav Ghildiyal
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
ssuserd6b1fd
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
Arun Umrao
 
2 d matrices
2 d matrices2 d matrices
2 d matrices
Himanshu Arora
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
Yung-Yu Chen
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
Dr.M.Karthika parthasarathy
 

Similar to C++ ARRAY WITH EXAMPLES (20)

C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
2D array
2D array2D array
2D array
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Arrays
ArraysArrays
Arrays
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
2 d matrices
2 d matrices2 d matrices
2 d matrices
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 

More from Farhan Ab Rahman

C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
Farhan Ab Rahman
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
Farhan Ab Rahman
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
Farhan Ab Rahman
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
Farhan Ab Rahman
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
Farhan Ab Rahman
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
Farhan Ab Rahman
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
Farhan Ab Rahman
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
Farhan Ab Rahman
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
Farhan Ab Rahman
 
VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2Farhan Ab Rahman
 
Kitab Bakurah.amani
Kitab Bakurah.amaniKitab Bakurah.amani
Kitab Bakurah.amani
Farhan Ab Rahman
 

More from Farhan Ab Rahman (12)

C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2
 
Notis Surau
Notis SurauNotis Surau
Notis Surau
 
Kitab Bakurah.amani
Kitab Bakurah.amaniKitab Bakurah.amani
Kitab Bakurah.amani
 

Recently uploaded

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
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
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)
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
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
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
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
 
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
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
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
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 

Recently uploaded (20)

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.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
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
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
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
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 

C++ ARRAY WITH EXAMPLES

  • 1. C++ : ARRAY WITH EXAMPLES SUMMATION OF TWO MATRIXES #include <iostream> using namespace std; int main() { int m,n,c,d, first[10][10], second[10][10], sum[10][10]; cout << "Enter the number of rows and columns of matrix" << endl; cin >> m>> n; cout << "Enter the elements of first matrix n"; for( c=0; c<m ; c++) for(d=0; d<n ; d++) cin >> first [c][d]; cout << "Enter the elements of second matrix n"; for(c=0; c<m; c++) for(d=0; d<n; d++) cin >> second[c][d]; for (c=0;c<m;c++) for(d=0;d<n;d++) sum[c][d]= first[c][d] + second[c][d];
  • 2. cout << "The summation of entered matrixes :- n"; for(c=0; c<m; c++) { for(d=0; d<n; d++) cout << sum[c][d] << "t"; cout << endl; } return 0; } //Output : Enter the number of rows and columns of matrix 3 3 Enter the elements of first matrix 1 2 3 4 5 6 7 8 9 Enter the elements of second matrix 1 2 3 4 5 6 7 8 9 The summation of entered matrixes :- 2 4 6 8 10 12 14 16 18
  • 3. DIFFERENCE OF TWO MATRIXES #include <iostream> using namespace std; int main() { int m,n,c,d, first[10][10], second[10][10], sum[10][10]; cout << "Enter the number of rows and columns of matrix" << endl; cin >> m>> n; cout << "Enter the elements of first matrix n"; for( c=0; c<m ; c++) for(d=0; d<n ; d++) cin >> first [c][d]; cout << "Enter the elements of second matrix n"; for(c=0; c<m; c++) for(d=0; d<n; d++) cin >> second[c][d]; for (c=0;c<m;c++) for(d=0;d<n;d++) sum[c][d]= first[c][d] - second[c][d]; cout << "The summation of entered matrixes :- n"; for(c=0; c<m; c++) {
  • 4. for(d=0; d<n; d++) cout << sum[c][d] << "t"; cout << endl; } return 0; } //Output: Enter the number of rows and columns of matrix 3 3 Enter the elements of first matrix 7 8 9 4 5 6 1 2 3 Enter the elements of second matrix 1 2 3 4 5 6 7 8 9 The summation of entered matrixes :- 6 6 6 0 0 0 -6 -6 -6
  • 5. TRANSPOSE OF A MATRIX #include <iostream> using namespace std; int main() { int c,d, matrix[3][3],transpose_matrix[3][3]; cout <<"Enter the elements of 3x3 matrix n"; for( c=0; c<3 ; c++) for(d=0; d<3 ; d++) cin >> matrix [c][d]; for (c=0;c<3;c++) for(d=0;d<3;d++) transpose_matrix[c][d]= matrix[d][c]; cout << "The transpose of the given 3x3 matrix :- n"; for(c=0; c<3; c++) { for(d=0; d<3; d++) cout << transpose_matrix[c][d] << "t"; cout << endl; } return 0; }
  • 6. //Output: Enter the elements of 3x3 matrix 1 2 3 4 5 6 7 8 9 The transpose of the given 3x3 matrix :- 1 4 7 2 5 8 3 6 9 // Alternative way to find transpose of a matrix: #include <iostream> using namespace std; int main() { int m,n,c,d, matrix[10][10],transpose_matrix[10][10]; cout << "Enter the number of rows and columns of matrix" << endl; cin >> m>> n; cout << "Enter the elements of matrix n"; for( c=0; c<m ; c++) for(d=0; d<n ; d++) cin >> matrix [c][d]; for (c=0;c<m;c++) for(d=0;d<n;d++)
  • 7. transpose_matrix[c][d]= matrix[d][c]; cout << "The transpose of the entered matrixes :- n"; for(c=0; c<m; c++) { for(d=0; d<n; d++) cout << transpose_matrix[c][d] << "t"; cout << endl; } return 0; } // Output: Enter the number of rows and columns of matrix 5 5 Enter the elements of matrix 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 The transpose of the entered matrixes :- 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25
  • 8. MULTIPLICATION OF TWO MATRIXES (2X2 DIMENSION ONLY) #include <iostream> using namespace std; int main() { int m,n,c,d, first[2][2], second[2][2], mult[2][2]; cout << "Enter the number of rows and columns of matrix" << endl; cin >> m>> n; cout << "Enter the elements of first matrix n"; for( c=0; c<m ; c++) for(d=0; d<n ; d++) cin >> first [c][d]; cout << "Enter the elements of second matrix n"; for(c=0; c<m; c++) for(d=0; d<n; d++) cin >> second[c][d]; for (c=0;c<m;c++) for(d=0;d<n;d++) mult[c][d]= first[c][0] * second[0][d] + first[c][1] * second[1][d]; cout << "Multiplication of entered matrixes :- n";
  • 9. for(c=0; c<m; c++) { for(d=0; d<n; d++) cout << mult[c][d] << "t"; cout << endl; } return 0; } //Output : Enter the number of rows and columns of matrix 2 2 Enter the elements of first matrix 1 2 3 4 Enter the elements of second matrix 1 2 3 4 Multiplication of entered matrixes :- 7 10 15 22
  • 10. INVERSE OF A MATRIX (2x2 DIMENSION ONLY) #include <iostream> using namespace std; int main() { int c,d, determinant, matrix[2][2], inv[2][2]; cout << "Enter the elements of 2x2 matrix n"; for( c=0; c<2 ; c++) for(d=0; d<2 ; d++) cin >> matrix [c][d]; determinant= matrix[0][0] * matrix[1][1] - matrix[0][1]*matrix[1][0]; for (c=0; c<2; c++) for(d=0; d<2; d++) { if ( c==0 && d==0) inv[c][d]= matrix[1][1]; else if (c==1 && d==1) inv[c][d]= matrix[0][0]; else inv[c][d]= - matrix[c][d]; }
  • 11. cout << "Inverse of entered matrixes :- n"; for(c=0; c<2; c++) { for(d=0; d<2; d++) cout << (float) inv[c][d]/determinant << "t"; cout << endl; } return 0; } //Output: Enter the elements of 2x2 matrix 1 2 3 4 Inverse of entered matrixes :- -2 1 1.5 -0.5