Hello (again) guys! Since I finished my last project (thanks to you, who helped me!) I started a new one and I'm stuck again ) The perks of being a newbie...
Here is what I want to do:
1.Insert number of rows & columns for matrix A
2.Check If the no. of rows and columns are higher than 10, 10 being the maximum allowed number of rows/columns.
3.Insert values for each position
4.Idem 1&2&3 for matrix B
5.Check if the rows of first matrix(A) equals the columns of the second matrix(B) -> If they are equal proceed. If not "Restart the program"
Question here: Is there any way to automatically start again the "program" if the rows(A) and columns(B) are not equal ? Like a goto ?
6.If they are equal set no. of rows for matrix C (the product matrix from A*B) as the no. of rows for matrix A, same for columns for matrix C from matrix B.
2nd Question here: I don't know how to write the rule for the calculation... I thought of something like C[i][j] = A[i][j] * B[i][j] + A[i+1][j] * B[i][j+1].
But this way it won't stop (I think) when it reaches the last position in the row/column :-/
Here is the CODE, thanks for being an wonderful community and for the help!
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
int A[10][10],B[10][10],C[10][10],RowA,ColA,RowB,ColB,i,j,RowC,ColC;
printf ("Enter the number of rows for the first matrix: ");
scanf ("%d", &RowA);
if ( RowA > 10 )
{
printf ("The value is too hight, the maximum size is 10!\nPlease insert new value: ");
scanf ("%d", &RowA);
}
while ( RowA > 10 );
printf ("Enter the number of columns for the first matrix: ");
scanf ("%d", &ColA);
if ( ColA > 10 )
{
printf ("The value is too hight, the maximum size is 10!\nPlease insert new value: ");
scanf ("%d", &ColA);
}
while ( ColA > 10 );
for (i=0 ; i<RowA ; i++)
for (j=0 ; j<ColA ; j++)
{
printf ("Enter the value for A[%d][%d]: ", i+1, j+1);
scanf ("%d", &A[i][j]);
}
printf ("Enter the number of rows for the second matrix: ");
scanf ("%d", &RowB);
if ( RowB > 10 )
{
printf ("The value is too hight, the maximum size is 10!\nPlease insert new value: ");
scanf ("%d", &RowB);
}
while ( RowB > 10 );
printf ("Enter the number of columns for the second matrix: ");
scanf ("%d", &ColB);
if ( ColB > 10 )
{
printf ("The value is too hight, the maximum size is 10!\nPlease insert new value: ");
scanf ("%d", &ColB);
}
while ( ColB > 10 );
for (i=0 ; i<RowB ; i++)
for (j=0 ; j<ColB ; j++)
{
printf ("Enter the value for B[%d][%d]: ", i+1, j+1);
scanf ("%d", &B[i][j]);
}
if ( RowA != ColB )
{
printf ("The number of rows for matrix A must equal de number of columns for matrix B!\nPlease restart the program!\n");
}
else
{
RowC = RowA;
ColC = ColB;
for (i=0 ; i<RowC ; i++);
{
for (j=0 ; j<ColC ; j++);
}
}
system ("pause");
}