Write a C++ program to print Transpose of a matrix(2 D array).*/
//Now select File->New in Notepad and type the C++ program
#include <iostream>
using namespace std;
int main()
{
int a[3][3], i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{ cout<<"enter the value for array["<<i+1<<"]"<<"["<<j+1<<"] :";
cin>>a[i][j];
}
}
system("cls");
cout<<"\n\nOriginal Array\n";
for(i=0; i<3; i++) {
for(j=0; j<3; j++)
cout<<a[i][j]<<' ';
cout<<endl; }
cout<<"\n\n The Transpose of Matrix\n";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
co
ut<<a[j][i]<<' ';
cout<<endl ;
}
return 0;
}
// Save this file as trans_cpp.cpp
//Now select File→New in Notepad and type the Python program
# Save the File as transpose.py.Program that compiles and executes a .cpp file
# Python tanspose.py -i trans_cpp
import sys, os, getopt
def main(argv):
cpp_file = ''
exe_file = ''
opts, args = getopt.getopt(argv, "i:",['ifile='])
for o, a in opts:
if o in ("-i", "--ifile"):
cpp_file = a + '.cpp'
exe_file = a + '.exe'
run(cpp_file, exe_file)
def run(cpp_file, exe_file):
print("Compiling " + cpp_file)
os.system('g++ ' + cpp_file + ' -o ' + exe_file)
print("Running " + exe_file)
print("-------------------")
print
os.system(exe_file)
print
if __name__ =='__main__':
main(sys.argv[1:])