Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

9 Apr 2013

PROGRAM TO PRINT UPPER TRIANGULAR MATRIX IN C++


Write a program to print upper triangular matrix in c++

#include<iostream.h>
#include<conio.h>
void main()
{   clrscr();
 int a[10][10],b[10][10],c[10][10];
 int i, j, n, m;
 int p,q;
 cout<<"enter no of rows of matrix\n";
 cin>>m;
 cout<<"enter no of colomns of matrix\n";
 cin>>n;
 cout<<"\n\nenter the elements of matrix\n";
  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      cout<<"a["<<i+1<<"]["<<j+1<<"]:= ";
      cin>>a[i][j];
     }
   }
  cout<<"\n\nmatrix u have entered is"<<endl;
  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      cout<<"\t"<<a[i][j];
     }
    cout<<endl;
   }
 cout<<"Upper tringular matrix is"<<endl;
  for(i=0;i<m;i++)
  {
   for(j=0;j<n;j++)
    {
     if(i<=j)
     {
      cout<<"\t"<<a[i][j];
     }
     else
     {
      cout<<"\t ";
     }
    }
    cout<<endl;
  }


getch();
}

==OUTPUT==

7 comments:

  1. do u really think that its a true upper triangula matrix??????? :o

    ReplyDelete
    Replies
    1. Nice job really appreciate it 😋😋

      Delete
    2. Khadija, you can print zeros in the place of empty spaces if you want in that upper triangular matrix

      Delete
    3. I gettit. Shouldn't that upper triangular matrix be along the main diagonal right?

      Delete
  2. Nice Job my friend.............
    your are a programmer............

    ReplyDelete