How to give matrix input from keyboard or file in python

P

Pramod

I want to write the following programm in python .


Main objective is input from keyoard to enter elements into the
matrix .


Thanks in advance



#include<iostream>
#include<math.h>
#include<cstdlib>
using namespace std;
int main()
{
double **a;
int i,j,n;
cout<<"Enter size of the matrix\n";
cin>>n;
a=new double* [n];
for(i=0;i<n;i++)
a=new double[n+1];
for(i=0;i<n;i++){
for(j=0;j<n;j++)
cin>>a[j];
cout<<endl;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++)
cout<<a[j]<<"\t";
cout<<endl;
}
delete [] a;
}



thanku Chris for your program. after running yourprogram following
errors are coming ,can expalined in detailes please .

Enter size of the matrix: 2
Traceback (most recent call last):
File "two.py", line 16, in <module>
stringified = "\n".join("\t".join(row) for row in a)
File "two.py", line 16, in <genexpr>
stringified = "\n".join("\t".join(row) for row in a)
TypeError: sequence item 0: expected string, float found

Thanks in Advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top