-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise23/exercise23
Binary file not shown.
46 changes: 46 additions & 0 deletions
46
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise23/exercise23.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Write a C program to read elements in two matrices and add elements of both matrices. | ||
C program for addition of two matrix. | ||
Matrix addition program in C. | ||
Logic to add two matrix in C programming. | ||
*/ | ||
|
||
#include<stdio.h> | ||
|
||
int main(){ | ||
|
||
int array1[3][3],array2[3][3]; | ||
|
||
printf("Enter elements in matrix A of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array1[i][j]); | ||
} | ||
|
||
} | ||
|
||
printf("Enter elements in matrix B of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array2[i][j]); | ||
} | ||
|
||
} | ||
|
||
printf("Sum of matrices A+B =\n"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
printf("%d ",(array1[i][j]+array2[i][j])); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
|
||
return 0; | ||
} |
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise24/exercise24
Binary file not shown.
45 changes: 45 additions & 0 deletions
45
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise24/exercise24.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Write a C program to read elements in two matrices and find the difference of two matrices. | ||
Program to subtract two matrices in C. | ||
Logic to subtract two matrices in C programming. | ||
*/ | ||
|
||
#include<stdio.h> | ||
|
||
int main(){ | ||
|
||
int array1[3][3],array2[3][3]; | ||
|
||
printf("Enter elements in matrix A of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array1[i][j]); | ||
} | ||
|
||
} | ||
|
||
printf("Enter elements in matrix B of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array2[i][j]); | ||
} | ||
|
||
} | ||
|
||
printf("Difference of both matrices A-B =\n"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
printf("%d ",(array1[i][j]-array2[i][j])); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
|
||
return 0; | ||
} |
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise25/exercise25
Binary file not shown.
39 changes: 39 additions & 0 deletions
39
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise25/exercise25.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Write a C program to read elements in a matrix and perform scalar multiplication of matrix. | ||
C program for scalar multiplication of matrix. | ||
How to perform scalar matrix multiplication in C programming. | ||
Logic to perform scalar matrix multiplication in C program. | ||
*/ | ||
|
||
#include<stdio.h> | ||
|
||
int main(){ | ||
|
||
int array1[3][3],multiply; | ||
|
||
printf("Enter elements in matrix A of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array1[i][j]); | ||
} | ||
|
||
} | ||
|
||
printf("Enter any number to multiply with matrix A:"); | ||
scanf("%d",&multiply); | ||
|
||
|
||
printf("Resultant matrix c.A =\n"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
printf("%d ",(array1[i][j] * multiply)); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
return 0; | ||
} |
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise26/exercise26
Binary file not shown.
61 changes: 61 additions & 0 deletions
61
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise26/exercise26.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Write a C program to read elements in two matrices and multiply them. | ||
Matrix multiplication program in C. | ||
How to multiply matrices in C. | ||
Logic to multiply two matrices in C programming. | ||
*/ | ||
|
||
#include<stdio.h> | ||
|
||
int main(){ | ||
|
||
int array1[3][3],array2[3][3],array3[3][3]; | ||
int sum ; | ||
printf("Enter elements in matrix A of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array1[i][j]); | ||
} | ||
|
||
} | ||
|
||
printf("Enter elements in matrix B of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array2[i][j]); | ||
} | ||
|
||
} | ||
|
||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
sum = 0; | ||
for (int k = 0; k < 3; k++) | ||
{ | ||
sum += (array1[i][k]*array2[k][j]); | ||
} | ||
array3[i][j] = sum; | ||
} | ||
|
||
} | ||
|
||
|
||
printf("Product of matrix A * B =\n"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
printf("%d ",array3[i][j]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
|
||
return 0; | ||
} |
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise27/exercise27
Binary file not shown.
59 changes: 59 additions & 0 deletions
59
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise27/exercise27.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Write a C program to enter elements in two matrices and check whether both matrices are equal or not. | ||
C program to check whether elements of two matrices are equal or not. | ||
Logic to check if two matrices are equal or not in C programming. | ||
*/ | ||
|
||
#include<stdio.h> | ||
|
||
int main(){ | ||
|
||
int array1[3][3],array2[3][3]; | ||
int flag; | ||
|
||
printf("Enter elements in matrix A of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array1[i][j]); | ||
} | ||
|
||
} | ||
|
||
printf("Enter elements in matrix B of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array2[i][j]); | ||
} | ||
|
||
} | ||
|
||
flag = 1; | ||
|
||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
if (array1[i][j] != array2[i][j]) | ||
{ | ||
flag = 0; | ||
break; | ||
} | ||
|
||
} | ||
} | ||
|
||
if (flag == 1) | ||
{ | ||
printf("Matrix A is equal to Matrix B"); | ||
} | ||
else | ||
{ | ||
printf("Matrix A is NOT equal to Matrix B"); | ||
} | ||
|
||
return 0; | ||
} |
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise28/exercise28
Binary file not shown.
38 changes: 38 additions & 0 deletions
38
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise28/exercise28.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Write a C program to read elements in a matrix and find the sum of main diagonal (major diagonal) elements of matrix. | ||
Find sum of all elements of main diagonal of a matrix. | ||
Logic to find sum of main diagonal elements of a matrix in C programming. | ||
*/ | ||
#include<stdio.h> | ||
|
||
int main(){ | ||
|
||
int array[3][3]; | ||
int sum = 0; | ||
|
||
|
||
printf("Enter elements in matrix of size 3x3:"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
scanf("%d",&array[i][j]); | ||
} | ||
|
||
} | ||
|
||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 3; j++) | ||
{ | ||
if (i == j) | ||
{ | ||
sum += array[i][j]; | ||
} | ||
} | ||
} | ||
|
||
printf("Sum of main diagonal elements = %d\n",sum); | ||
|
||
return 0; | ||
} |
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise29/exercise29
Binary file not shown.
40 changes: 40 additions & 0 deletions
40
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise29/exercise29.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Write a C program to read elements in a matrix and find the sum of minor diagonal (opposite diagonal) elements. | ||
C program to calculate sum of minor diagonal elements. | ||
Logic to find sum of opposite diagonal elements of a matrix in C programming. | ||
*/ | ||
|
||
#include<stdio.h> | ||
#define SIZE 3 | ||
|
||
int main(){ | ||
|
||
int array[SIZE][SIZE]; | ||
int sum = 0; | ||
|
||
|
||
printf("Enter elements in matrix of size 3x3:"); | ||
for (int i = 0; i < SIZE; i++) | ||
{ | ||
for (int j = 0; j < SIZE; j++) | ||
{ | ||
scanf("%d",&array[i][j]); | ||
} | ||
|
||
} | ||
|
||
for (int i = 0; i < SIZE; i++) | ||
{ | ||
for (int j = SIZE-1; j >= 0; j--) | ||
{ | ||
if ((i+j)==(SIZE-1) ) | ||
{ | ||
sum += array[i][j]; | ||
} | ||
} | ||
} | ||
|
||
printf("Sum of minor elements = %d\n",sum); | ||
|
||
return 0; | ||
} |
Binary file added
BIN
+48.4 KB
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise30/exercise30
Binary file not shown.
46 changes: 46 additions & 0 deletions
46
codeforwin_c_exercises/array_and_matrix_programming_exercises/exercise30/exercise30.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Write a C program to read elements in a matrix and find the sum of elements of each row and columns of matrix. | ||
C program to calculate sum of rows and columns of matrix. | ||
Logic to find sum of each row and columns of a matrix in C programming. | ||
*/ | ||
#include<stdio.h> | ||
#define SIZE 3 | ||
|
||
int main(){ | ||
|
||
int array[SIZE][SIZE]; | ||
int sum; | ||
|
||
|
||
printf("Enter elements in matrix of size 3x3:"); | ||
for (int i = 0; i < SIZE; i++) | ||
{ | ||
for (int j = 0; j < SIZE; j++) | ||
{ | ||
scanf("%d",&array[i][j]); | ||
} | ||
|
||
} | ||
|
||
for (int i = 0; i < SIZE; i++) | ||
{ | ||
sum = 0; | ||
for (int j = 0; j < SIZE; j++) | ||
{ | ||
sum += array[i][j]; | ||
} | ||
printf("Sum of elements of Row %d = %d\n",i+1,sum); | ||
} | ||
|
||
for (int i = 0; i < SIZE; i++) | ||
{ | ||
sum = 0; | ||
for (int j = 0; j < SIZE; j++) | ||
{ | ||
sum += array[j][i]; | ||
} | ||
printf("Sum of elements of Column %d = %d\n",i+1,sum); | ||
} | ||
|
||
return 0; | ||
} |