- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
Following C++ program ask to the user to enter any two 3*3 array elements to subtract them i.e., Matrix1 - Matrix2, then display the subtracted result of the two matrices (Matrix3) on the screen:
Source Code: Print Hello World
/* C++ Program - Subtract Two Matrices */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int arr1[3][3], arr2[3][3], arr3[3][3], sub, i, j; cout<<"Enter 3*3 Array 1 Elements : "; for(i=0; i<3; i++) { for(j=0; j<3; j++) { cin>>arr1[i][j]; } } cout<<"Enter 3*3 Array 2 Elements : "; for(i=0; i<3; i++) { for(j=0; j<3; j++) { cin>>arr2[i][j]; } } cout<<"Subtracting array (array1-array2) ... \n"; for(i=0; i<3; i++) { for(j=0; j<3; j++) { arr3[i][j]=arr1[i][j]-arr2[i][j]; } } cout<<"Result of Array1 - Array2 is :\n"; for(i=0; i<3; i++) { for(j=0; j<3; j++) { cout<<arr3[i][j]<<" "; } cout<<"\n"; } getch(); }Output
Enter 3*3 Array 1 Elements :2 2 2 2 2 2 2 2 2 Enter 3*3 Array 2 Elements : 1 1 1 1 1 1 1 1 1 Subtracting array (array1-array2) ... Result of Array1 - Array2 is : 1 1 1 1 1 1 1 1 1