-
Notifications
You must be signed in to change notification settings - Fork 0
/
22_nisham_ghimire_assignment.c
132 lines (111 loc) · 2.72 KB
/
22_nisham_ghimire_assignment.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//DETERMINANT OF A MATRIX
#include <stdio.h>
int determinant2(int matrix[2][2]){
int determinant;
determinant = matrix[0][0]*matrix[1][1] - matrix[1][0]*matrix[0][1];
printf("%d",determinant);
}
int main(){
printf("Enter matrix");
int i,j,matrix[2][2];
for (i =0; i< 2;i++){
for ( j = 0; j < 2; j++)
{
printf("Enter matrix [%d][%d] : ",i,j);
scanf("%d",&matrix[i][j]);
}
}
determinant2(matrix);
return 0;
}
//TRANSPOSE OF A MATRIX
#include <stdio.h> //Program to print transpose of a Matrix of size [3][4];
#include <stdlib.h>
void main(){
int matrix[3][4]={1,2,3,4,5,6,7,8,9,10,11,12}; //matrix
int c,d,transpose[4][3]; //next matrix
printf("Transpose of the matrix :\n");
for (c = 0; c < 4; c++) { //row+1 [4] as row+
for (d = 0; d < 3; d++){ //cloumn-1 [3] as column-
transpose[c][d]=matrix[d][c]; //storing the result
printf(" %d ", *(*(transpose + c)+d)); //final sum print
}
printf("\n"); //linegap
}
}
#include <stdio.h> //Program to print sum
void main(){
int matrix[2][2]; //matrix
int matrix2[2][2]; //2nd matrix
int i,j;
for (i = 0; i < 2; i++){
for (j = 0; j < 2; j++)
{
printf("enter matrix [%d] [%d] ",i,j);
scanf("%d",&matrix[i][j]);
}
}
for (i = 0; i < 2; i++){
for (j = 0; j < 2; j++)
{
printf("enter matrix2 [%d] [%d] ",i,j);
scanf("%d",&matrix2[i][j]);
}
}
//MATRIX SUM AND DIFFERENCE
printf("SUM = \n");
int temp[2][2];
// int *ptr;
for (int c = 0; c < 2; c++) {
for (int d = 0; d < 2; d++){
temp[c][d] = matrix2[c][d] + matrix[c][d]; //storing the result
printf("%d\t", temp[c][d]);
}
printf("\n"); //linegap
}
printf("\n");
printf("DIFFERENCE = \n");
// int *ptr;
for (int c = 0; c < 2; c++) {
for (int d = 0; d < 2; d++){
temp[c][d] = matrix[c][d] - matrix2[c][d]; //storing the result
printf("%d\t", temp[c][d]);
}
printf("\n"); //linegap
}
}
//MATRIX MULTIPLICATION
#include <stdio.h>
int main(){
int c[3][3],a[3][3],b[3][3],i=0,k=0,j=0,sum=0;
printf("Enter first matrix a : \n");
for (i=0;i<3;i++){
for(j=0;j<3;j++){
scanf("%d",&a[i][j]);
}
}
printf("Enter first matrix b : \n");
for (i=0;i<3;i++){
for(j=0;j<3;j++){
scanf("%d",&b[i][j]);
}
}
for (i=0;i<3;i++){
for (j=0;j<3;j++){
for (k = 0; k < 3; k++){
sum += a[i][j] * b[j][k];
// *(*c(i)+k) += *(*a(i)+k) + *(*b(i)+k);
}
c[i][j] = sum;
sum =0;
}
}
printf("MULTIPLICATION = \n");
for (i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%d\t",c[i][j]);
}
printf("\n");
}
return 0;
}