Here i have a working code, what i want to know is:
When the user inputs elements to the array, i want it to be automatically aligned in form of an matrix.
Instead of
1
2
3
4
5
6
etc....
But just as a matrix, like this
1 2 3
4 5 6
I tried to accomplish that for some time now, and so far not successful.
I tried with escape sequences, but there is no way i can go to a previous line with escape sequence, so that i can use \b
.
Google and daniweb searches, didn't help at all, except for a slight information about gotoxy(), so my question is, is it even possible for to do that in run time?
And if yes how? And how can i use gotoxy() (With syntax, it's much appreciated, & what are the arguments for this function)?
// Matrix-Addition.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a[10][10],b[10][10],c[10][10], r, g, d, e;
cout<<"Enter the dimensions for the first matrix"<<endl;
cin>>r;
cin>>g;
cout<<"Enter the dimensions for the second matrix"<<endl;
cin>>d;
cin>>e;
if((r==d)&&(g==e))
{
cout<<"Enter the elements for the first matrix"<<endl;
for(int i=0;i<r;i++)
{
for(int j=0;j<g;j++)
{
cin>>a[i][j];
}
}
cout<<endl<<endl;
cout<<"In Matrix:"<<endl<<endl;
for(int i=0;i<r;i++)
{
cout<<endl;
for(int j=0;j<g;j++)
{
cout<<a[i][j]<<" ";
}
}
cout<<endl<<endl;
cout<<"Enter the elements for the second matrix"<<endl;
for(int i=0;i<r;i++)
{
for(int j=0;j<g;j++)
{
cin>>b[i][j];
}
}
cout<<endl<<endl;
cout<<"In Matrix:"<<endl<<endl;
for(int i=0;i<r;i++)
{
cout<<endl;
for(int j=0;j<g;j++)
{
cout<<b[i][j]<<" ";
}
}
for(int i=0;i<r;i++)
{
for(int j=0;j<g;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
cout<<endl<<endl;
cout<<"The matrix after addition is "<<endl;
for(int i=0;i<r;i++)
{
cout<<endl;
for(int j=0;j<g;j++)
{
cout<<c[i][j]<<" ";
}
}
}
else
{
cout<<"The dimensions entered mismatch, addition impossible";
}
getch();
return 0;
}