well i know how to declarate the 2-dim. arrays and the most difficult part for me is a)
this is what I did :
#include<iostream.h>
#include<math.h>
double X[50][50];
double Y[50][50];
double Z[50][50];
int M,N,P,Q,i,j;
main () {
cout<<"Broi redove v matr.X=";
cin>>M;
cout<<"Broi stulbove v matr.X=";
cin>>N;
for (i=0;i<M;i++)
for (j=0;j<N;j++) {
cout<<"X["<<i<<"]["<<j<<"]=";
cin>>X[i][j];
}
cout<<"Broi redove v matr.Y=";
cin>>P;
cout<<"Broi stulbove v matr.Y=";
cin>>Q;
for (i=0;i<P;i++)
for (j=0;j<Q;j++) {
cout<<"Y["<<i<<"]["<<j<<"]=";
cin>>Y[i][j];
}
First of all, wrap code in [code][/code] tags to make it pretty.
So, a.
Step 1. Write a program that prints even rows of X.
Step 2. Write a function that, given an integer i, prints the i'th row of X and i'th column of Y.
Step 3. Write a function that swaps the first row of X with the first row of Y (or any two arrays).
Step 4. Combine the steps before into the solution to a. You should mostly only need ctrl+C, ctrl+V to do that.
Extra awesome step. Realize that 2d arrays are just fancy syntax for 1d arrays ([x][y] becomes [x+y*width]). Use this knowledge to replace static arrays with dynamic ones and allow the user to enter M.
I don`t know how to do step 1 , is it sth like this ?
#include<iostream.h>
#include<math.h>
double X[50][50];
double Y[50][50];
double Z[50][50];
int M,N,P,Q,S,k,i,j;
main () {
cout<<"Broi redove i stulbove v matr.X=";
cin>>M;
for (i=0;i<M;i++)
for (j=0;j<M;j++) {
cout<<"X["<<i<<"]["<<j<<"]=";
cin>>X[i][j];
}
for (i=0;i<M;i++)
for (j=0;j<M;j++) {
cout<<"Y["<<i<<"]["<<j<<"]=";
cin>>Y[i][j];} this is declaration
for (i=0;i<M;i++)
{
if (M%2==0)
cout<<X[i][j]<<endl;} is that how i print the even rows of X?
Know that I am not very good at this program , that is why I need help.
What is missing is another for loop. You need to iterate through the row to print it.
I hadn't noticed before. Why are you checking M % 2? M is the size of your matrix. It does not indicate the row you are in or anything else. 'i' does.