ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Tuesday 26 April 2016

CSE1002:PP7: SYMMETRIC MATRIX

SYMMETRIC MATRIX

Given a square matrix check if it is symmetric or not. Represent a matrix as a vector of vectors. Use vector in STL to represent a matrix.


PSEUDOCODE:


START
Read n
INITIALIZE 2d VECTOR m i.e. vector<vector<int> > m(n,vector<int>(n,0));
SET f=1;
INITIALIZE COLUMN VECTOR i.e. vector<int> col;
FOR j=0 to n-1
CLEAR COL i.e. col.clear();
FOR i=0 to n-1
READ t
PUSH t into col
END FOR
PUSH col into m
END FOR
FOR i=0 to n-1
FOR j=0 to n-1
IF(m[i][j]!=m[j][i] && f==1) THEN
PRINT "Not symmetric";
SET f=0
END IF
END FOR
END FOR
IF(f==1) THEN
PRINT"Symmetric"

STOP


CODE:


#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
cin>>n;
vector<vector<int> > m(n,vector<int>(n,0));
int i;
int j;
int f=1;
vector<int> col;
for(j=0;j<n;j++)
{
col.clear();
int t;
for(i=0;i<n;i++)
{cin>>t;
m[j][i]=t;
col.push_back(t);
}
m.push_back(col);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
//cout<<m[i][j]<<" , "<<m[j][i]<<endl;
if(m[i][j]!=m[j][i] && f==1)
{
cout<<"Not symmetric";
f=0;
break;
}
}
}
if(f==1)
cout<<"Symmetric";
return 0;

}

No comments:

Post a Comment