ma tran

Màu nền
Font chữ
Font size
Chiều cao dòng

#include <stdio.h>

#include <conio.h>

#include <iostream.h>

#include <iomanip.h>

  class matran

    {

     private:

       int sd;

       int sc;

       float a[100][100];

     public:

     friend istream & operator >>(istream & is,matran &);

     friend ostream & operator<<(ostream & os, matran &);

     int ktra();

    };

   istream & operator>>(istream & is,matran & x)

   {

     cout<<"

so dong: "; is>>x.sd;

     cout<<"

so cot: "; is>>x.sc;

     for(int i=0;i<x.sd;i++)

     for(int j=0;j<x.sc;j++)

     { cout<<"

nhap a["<<i<<"]["<<j<<"] = ";

       is>>x.a[i][j];

     }

     return is;

   }

  ostream & operator<<(ostream & os,matran & x)

   {

    for(int i=0;i<x.sd;i++)

    for(int j=0;j<x.sc;j++)

    {

      if(j==0) os<<"

";

      os<<x.a[i][j]<<"     ";

    }

    return os;

   }

  int matran::ktra()

   {

      if(sd==sc)

     {

        int  tong=0;

        int   tich=1;

        for(int i=0;i<sd;i++)

        for(int j=0;j<sc;j++)

           {

                   tong+=a[i][j];

                   tich*=a[i][i];

           }

       if((tong==sc)&&(tich==1))   return 1;

     }

      else return 0;

    }

   void main()

    {

     matran x;

     clrscr();

     cout<<"

nhap ma tran x; ";cin>>x;

     if(x.ktra()==1) cout<<"

x la ma tran don vi";

       else cout<<"

x ko la ma tran don vi";

     cout<<"

hien thi ma tran x; "<<x;

     getch();

    }

Bạn đang đọc truyện trên: Truyen2U.Pro