Commit 470dcad1 by matjul

Upload New File

parent 97e66cf0
Showing with 155 additions and 0 deletions
#include <stdio.h>
#include <string.h>
int main(){
int i;
int j;
int x;
printf("Choose the size of the matrices: ");
scanf("%d", &x);
i = x;
j = x;
int matrice1[x][x];
printf("Now fill the rows of the first matrice with the numbers: \n");
for(i = 0; i < x ; i++) {
for(j = 0; j < x; j++) {
scanf("%d", &matrice1[i][j]);
}
}
printf("the first matrice is:\n");
for(i = 0; i < x ; i++) {
for(j = 0; j < x; j++) {
printf("%d, ", matrice1[i][j]);
}
printf("\n");
}
int matrice2[x][x];
printf("Now fill the rows of the second matrice with the numbers: \n");
for(i = 0; i < x ; i++) {
for(j = 0; j < x; j++) {
scanf("%d", &matrice2[i][j]);
}
}
printf("The second matrice is:\n");
for(i = 0; i < x ; i++) {
for(j = 0; j < x; j++) {
printf("%d, ", matrice2[i][j]);
}
printf("\n");
}
int sumOfMatrices[x][x];
printf("The sum of the matrices is:\n");
for(i = 0; i < x ; i++){
for(j = 0; j < x; j++){
sumOfMatrices[i][j] = matrice1[i][j] + matrice2[i][j];
printf("%d, ", sumOfMatrices[i][j]);
}
printf("\n");
}
int diffOfMatrices[x][x];
printf("The difference of the matrices is:\n");
for(i = 0; i < x ; i++){
for(j = 0; j < x; j++){
diffOfMatrices[i][j] = matrice1[i][j] - matrice2[i][j];
printf("%d, ", diffOfMatrices[i][j]);
}
printf("\n");
}
int array1[x];
int array2[x];
for(i = 0; i < x; i++){
for(j = 0; j < x; j++){
if( i == j){
array1[i] = matrice1[i][j];
printf("%d, ", array1[i]);
}
if(i + j == x - 1){
array2[i] = matrice1[i][j];
}
}
}
printf("\n");
for(i = 0; i < x; i++){
printf("%d, ", array2[i]);
}
int sumOfFirstDiagOfFirstMatrice = 1;
for(i = 0; i < 3; i++){
sumOfFirstDiagOfFirstMatrice *= array1[i];
}
printf("The sum of the first diagonal\n");
printf("%d, ", sumOfFirstDiagOfFirstMatrice);
int sumOfSecondDiagOfFirstMatrice = 1;
for(i = 0; i < 3; i++){
sumOfSecondDiagOfFirstMatrice *= array2[i];
}
printf("The sum of the second diagonal\n");
printf("%d, ", sumOfSecondDiagOfFirstMatrice);
int sumOfTwoDiagOfFirstMatrice;
sumOfTwoDiagOfFirstMatrice = sumOfFirstDiagOfFirstMatrice + sumOfSecondDiagOfFirstMatrice;
printf("The sum of the two diagonals\n");
printf("%d\n", sumOfTwoDiagOfFirstMatrice);
int productOfMain1 = 1;
int productOfOff1 = 1;
int productOfMain2 = 1;
int productOfOff2 = 1:
for(i = 0; i< x; i++){
productOfMain1 *= matrice1[i][i];
productOfMain2 *= matrice2[i][i];
productOfOff1 *= matrice1[i][x-1-i];
productofOff2 *= matrice2[i][x-1-i];
}
sum1 = productOfMain1 + productOfOff1;
sum2 = productOfMain2 + productOfOff2;
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