Commit 793765d8 by phkarl

Upload New File

parent 1aa45025
Showing with 130 additions and 0 deletions
#include <stdio.h>
int main(){
int matrix_size;
int value;
int product = 1;
int product2 = 1;
int num;
printf("Please enter dimension of matrices: ");
scanf("%d", &matrix_size);
int array1[matrix_size][matrix_size];
int array2[matrix_size][matrix_size];
// Values for first Matrix
printf("Please enter values for the first matrix: \n");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
printf("Please enter value: ");
scanf("%d", &array1[i][j]);
}
}
printf("\nThis is your first Matrix: \n");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
printf("%d, ", array1[i][j]);
}
printf("\n");
}
printf("\n");
// Values for second Matrix
printf("Please enter values for the second matrix: \n");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
printf("Please enter value: ");
scanf("%d", &array2[i][j]);
}
}
printf("\nThis is your second Matrix: \n");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
printf("%d, ", array2[i][j]);
}
printf("\n");
}
printf("\n");
// Add
printf("The sum of the two matrices is: \n");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
value = array1[i][j] + array2[i][j];
printf("%d, ", value);
}
printf("\n");
}
printf("\n");
// Difference
printf("The Difference of the two matrices is: \n");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
value = array1[i][j] - array2[i][j];
printf("%d, ", value);
}
printf("\n");
}
printf("\n");
// The sum of the multiplication of elements on the diagonals of the two matrices
printf("The sum of the multiplication of elements on \n");
printf("the diagonals of the two matrices is: \n");
printf("First Matrix: ");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
if(i == j){
product *= array1[i][j];
}
}
}
num = matrix_size - 1;
for(int i = 0; i < matrix_size; i++){
product2 *= array1[i][num];
num--;
}
product = product + product2;
printf("%d\n", product);
product = 1;
product2 = 1;
printf("Second Matrix: ");
for(int i = 0; i < matrix_size; i++){
for(int j = 0; j < matrix_size; j++){
if(i == j){
product *= array2[i][j];
}
}
}
num = matrix_size - 1;
for(int i = 0; i < matrix_size; i++){
product2 *= array2[i][num];
num--;
}
product = product + product2;
printf("%d", product);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment