Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<ctype.h>
# define ROW_MAX 5
# define Column_MAX 5
int rows=0,size=0;
int columns =0;
int arrayA[ROW_MAX][Column_MAX];
int arrayB[ROW_MAX][Column_MAX];
int arrayC[ROW_MAX][Column_MAX];
void display(void);
void Populate_Matrix(void);
void Main_menu(void);
void operations();
void addition();
void subtraction();
void ScalarMult();
void main()
{// start of main
Main_menu();
}//end of main
void Main_menu(void)
{
char choice;
do
{
printf("\tA. Populate the matrix\n");
printf("\tB. Display the matrix\n");
printf("\tC. Perform operation\n");
printf("\tD. Credits\n");
printf("\tE. Exit Program\n\n\n");
printf("Please enter your choice: ");
scanf(" %c",&choice);
choice = toupper(choice);
//system("cls");
switch(choice)
{
case 'A':{
Populate_Matrix();
break;
}
case 'B':
{
display();
break;
}
case 'C':
{
operations();
break;
}
case 'D':
{
printf("done by Akeem Gordon CMCS 0506476\n\n\n\n");
break;
}
case 'E':
{
break;
}
default:
{
printf("Please choose a letter from A-E,You enterd a letter that is not accepted\n");
}
}
}while(choice !=0);
}
void Populate_Matrix(void)
{
int i,j;
do
{
printf("Enter the number of matrix you need\n");
scanf("%d",&size);
}while(size <0 || size >5);
printf("Enter the number of row and colums of mantrix\n");
scanf("%d%d",&rows,&columns);
if(size > 0 && size <= 5 )
{
printf("\tA. Add values to matrix A\n");
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
scanf("%d",&arrayA[i][j]);
}
}
}
if(size>1 && size <=5)
{
printf("\tA. Add values to matrix B\n");
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
scanf("%d",&arrayB[i][j]);
}
}
}
if(size>2 && size <=5)
{
printf("\tA. Add values to matrix C\n");
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
scanf("%d",&arrayC[i][j]);
}
}
}
}
void display(void)
{
int i, j;
if(size > 0 && size <= 5 )
{
printf("\t Add values to matrix A\n");
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",arrayA[i][j]);
}
printf("\n");
}
}
printf("\n");
if(size>1 && size <=5)
{
printf("\t values to matrix B\n");
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",arrayB[i][j]);
}
printf("\n");
}
}
printf("\n");
if(size>2 && size <=5)
{
printf("\tValues stores matrix C\n");
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",arrayC[i][j]);
}
printf("\n");
}
}
printf("\n");
}
void operations()
{
int choice=0;
do
{
printf("\t1 Scalar\n");
printf("\t2 Addition\n");
printf("\t3 Substraction\n");
printf("\t4 Multiplication\n");
printf("\t5 Exit Program\n\n\n");
scanf(" %d",&choice);
switch(choice)
{
case 1: ScalarMult();
break;
case 2:addition();
break;
case 3:subtraction();
break;
case 4:multiplication();
break;
default:
{
printf("Please choose a letter from A-E,You enterd a letter that is not accepted\n");
}
}
}while(choice !=0);
}
void addition()
{
int i,j;
int result[5][5]={0};
int choice1, choice2;
printf("Enter the two matrix you need to use\n");
scanf("%d %d", &choice1,&choice2);
if(choice1 == 1 && choice2 ==2)
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",result[i][j] = arrayA[i][j] + arrayB[i][j]);
}
printf("\n");
}
}
if(choice1 == 1 && choice2 ==3)
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",result[i][j] = arrayA[i][j] + arrayC[i][j]);
}
printf("\n");
}
}
if(choice1 == 2 && choice2 ==3)
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
result[i][j] = arrayC[i][j] + arrayB[i][j];
}
}
}
}
void subtraction()
{
int i,j;
int result[5][5]={0};
int choice1, choice2;
printf("Enter the two matrix you need to use\n");
scanf("%d %d", &choice1,&choice2);
if(choice1 == 1 && choice2 ==2)
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",result[i][j] = arrayA[i][j] - arrayB[i][j]);
}
printf("\n");
}
}
if(choice1 == 1 && choice2 ==3)
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",result[i][j] = arrayA[i][j] - arrayC[i][j]);
}
printf("\n");
}
}
if(choice1 == 2 && choice2 ==3)
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
result[i][j] = arrayC[i][j] - arrayB[i][j];
}
}
}
}
void ScalarMult()
{
int i,j;
int result[5][5]={0};
int choice1, scaleFactor;
printf("Enter the two matrix you need to SCALE and scale factor\n");
scanf("%d %d", &choice1,&scaleFactor);
if(choice1 == 1 )
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",arrayA[i][j] * scaleFactor);
}
printf("\n");
}
}
if(choice1 == 2 )
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",arrayB[i][j] * scaleFactor);
}
printf("\n");
}
}
if(choice1 == 3)
{
for(i=0; i < rows; i++)
{
for(j=0;j < columns; j++)
{
printf("%d ",arrayC[i][j] * scaleFactor);
}
}
}
}
void multiplication()
const int _M1ROWS = 2;
const int _M1COLS = 3;
const int _M2ROWS = 3;
const int _M2COLS = 2;
int main()
{
int Matrix1[_M1ROWS][_M1COLS] = {1,2,3,
4,5,6};
/
int Matrix2[_M2ROWS][_M2COLS] = {1,2,
3,4,
5,6};
int rMatrix [_M1ROWS][_M2COLS];
/
int rowM1, rowColIndx, colM2;
for(rowM1=0;rowM1<_M1ROWS;rowM1++)
{
for(colM2=0;colM2<_M2COLS;colM2++)
{
int calResult = 0;
for(rowColIndx=0;rowColIndx<_M1COLS;rowColIndx++)
{
calResult = calResult +(Matrix1[rowM1][rowColIndx] * Matrix2[rowColIndx][colM2]);
}
rMatrix[rowM1][colM2]=calResult;
}
}
printf("%d,",rMatrix[0][0]);
printf("%d\n",rMatrix[0][1]);
printf("%d,",rMatrix[1][0]);
printf("%d",rMatrix[1][1]);
int x;
scanf("%d");
}