Im trying to multiply a 5X5 matrix filled with random numbers with another matrix, also filled with random numbers. I'm still trying to fill the two matrices and then display them my code is as follows
Please help me.
I've also attached my code as a text file
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
void printArray( const int a[5][],int row, int column); /* function prototype */
void initializeArray( int a[5][],int row, int column); /* function prototype */
int main()
{
int rowA=5; /* counter */
int columnA=5;
int rowX = 5;
int columnX = 0;
printf("\nEnter the number of columns for the dense vector X MAX 100: ");
scanf("%d",&columnX);
while( !(columnX >=1) && !(columnX%2 == 0))
{
printf("\nIncorrect input");
printf("\nPlease enter an integer value greater than or equal to one (1)");
printf("\nEnter the number of columns for the dense vector X: ");
scanf("%d",&columnX);
}
/*initialise the dense vectors to 0 at the beginning- to get rid of junk data */
int arrayA[5][5]={0}; /* A is going to be a dense array of 25 integers */
int vectorX[5][100]={0}; /* X is going to be a dense array having at most 500 numbers*/
/*seed the random number generator with the system time*/
srand( time( NULL ) );
/*initialise elements of each dense vector*/
initializeArray(arrayA[5][5],rowA,columnA);
initializeArray(&vectorX[5][],rowX,columnX);
/*display results */
printf( "Values in the arrayA by row are:\n" );
printArray( arrayA[5][],rowA, columnA);
printf( "Values in vectorX by row are:\n" );
printArray(vectorX[5][],rowX, columnX);
getch();
return 0;
}
void initializeArray(int a[5][],int row, int column)
{
int i=0; /* row counter */
int j=0; /* column counter */
/* loop through rows */
for ( i = 0; i < 5; i++ ) {
/* and then input column values */
for ( j = 0; j < column; j++ ) {
a[ i][j] = 1 + ( rand() % 6 );
} /* end inner for */
} /*end outer for */
}
void printArray( const int a[5][],int row, int column )
{
int i=0; /* row counter */
int j=0; /* column counter */
/* loop through rows */
for ( i = 0; i < 5; i++ ) {
/* output column values */
for ( j = 0; j < column; j++ ) {
printf( "%d ", a[ i ][ j ] );
} /* end inner for */
printf( "\n" ); /* start new line of output */
} /* end outer for */
} /* end function printArray */
I've also attached my code as a text file
Comment