- 1
I need help solving this question in c++
An n*n matrix can be represented using 1-D array of size n(n+1)/2 by sorting either the lower or upper triangle of the matrix . The elements that are not explicitly stored may be computed from those that are stored . How do we compute this ?
4 Réponses
+ 1
Please show us your try, or it will seem as though this is your homework assignment that you want answers to, and not how to improve you try.
+ 1
actually I tried two times
+ 1
#include<iostream>
using namespace std;
int main()
{
int r1,r2,r3;
int m=[r1;r2;r3];
r1=[1,2,3,4];
r2=[5,6,7,8];
r3=[4,3,2,1];
cout<<"Enter the elements of 3X3 matrix: "<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>m[i][j];
}
}
cout<<endl;
for(int row=0;row<3;row++)
{
for(int col=0;col<3;col++)
{
if(row<col)
{
cout<<m[row][col]<<" ";
}
}
cout<<endl;
}
return 0;
}
+ 1
#include <iostream>
using namespace std;
int main()
{
//uppar 3X3 triangular matrix
int a[6];
for(int i=0;i<6;++i){
cout<<"enter values";
if(i==4){
a[i]=0;
}
else
{
cin>>a[i];
}
}
for(int i=0;i<6;++i){
cout<<a[i]<<endl;
}
return 0;
}