A simple program to find out the diagonal matrix. A diagonal matrix is that type of matrix which has non-zero elements in the diagonal only.
#include<iostream.h> #include<conio.h> void main() { clrscr(); int m[3][3]; for(int i=0;i<=2;i++) { for(int j=0;j<=2;j++) { cout << "enter matrix elements"; cin >> m[i][j]; } } for(i=0;i<=2;i++) { for(int j=0;j<=2;j++) { if(i==j) { cout << m[i][j] << " "; } else { cout << 0 << " "; } } cout << endl; } getch(); }