Question: modify the program so that the user is asked to type in the value of the base, if an invalid base number is entered the
modify the program so that the user is asked to type in the value of the base, if an invalid base number is entered the program will ask again until a correct value is entered.
#include
int main(void)
{
void scalarmultiply (int nrows, int ncols, int matrix[nrows][ncols], int scalar);
void displaymatrix (int nrows, int ncols, int matrix[nrows][ncols]);
int samplematrix[3][5] =
{
{7, 16, 55, 13, 12},
{12, 10, 52, 0, 7},
{-1, 1, 2, 4, 9}
};
printf("original matrix: ");
displaymatrix (3, 5, samplematrix);
scalarmultiply (3, 5, samplematrix, 2);
printf(" Multiplied by 2: ");
displaymatrix(3,5, samplematrix);
scalarmultiply (3,5, samplematrix, -1);
printf (" then multiplied by -1: ");
displaymatrix(3,5,samplematrix);
return 0;
}
void scalarmultiply (int nrows, int ncols, int matrix[nrows][ncols], int scalar)
{
int row, column;
for (row = 0; row < nrows; ++row)
for(column = 0; column < ncols; ++column)
matrix[row][column] *= scalar;
}
void displaymatrix ( int nrows, int ncols, int matrix[nrows][ncols])
{
int row, column;
for( row = 0; row < nrows; ++row)
{
for( column = 0; column < ncols; ++column)
printf("%5i", matrix[row][column]);
printf(" ");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
