-
Notifications
You must be signed in to change notification settings - Fork 2
/
Matrix.c
93 lines (78 loc) · 2.31 KB
/
Matrix.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct {
int rows;
int cols;
int data[];
} Matrix2D;
void printString(char str[])
{
printf("String is : %s \n",str);
}
int length(char str[])
{
int i=0;
while (str[i] != '\0')
++i;
return i;
}
void reverseSentence()
{
char c;
scanf("%c", &c);
if( c != '\n')
{
reverseSentence();
printf("%c",c);
}
}
int Random_NextIn(int From,int To){
srand(time(NULL));
return rand()%((To-From)+1)+From;
}
int main(void )
{
int Row,Column;
printf("Enter the Row and column of Matrix (R*C)\n");
scanf("%d*%d",&Row,&Column);
int Matrix_1[Row][Column];
int Matrix_2[Row][Column];
int Matrix_sum[Row][Column];
for (int i = 0; i < Row; i++) { //this equals to the row in our matrix.
for (int j = 0; j < Column; j++) { //this equals to the column in each row.
Matrix_1[i][j]=Random_NextIn(1,10);
}
}
for (int i = 0; i < Row; i++) { //this equals to the row in our matrix.
for (int j = 0; j < Column; j++) { //this equals to the column in each row.
Matrix_2[i][j]=Random_NextIn(10,20);
}
}
for (int i = 0; i < Row; i++) { //this equals to the row in our matrix.
for (int j = 0; j < Column; j++) { //this equals to the column in each row.
printf("%d ",Matrix_1[i][j]);
}
printf("\n");
}
printf("\n");
for (int i = 0; i < Row; i++) { //this equals to the row in our matrix.
for (int j = 0; j < Column; j++) { //this equals to the column in each row.
printf("%d ",Matrix_2[i][j]);
}
printf("\n");
}
for (int i = 0; i < Row; i++) { //this equals to the row in our matrix.
for (int j = 0; j < Column; j++) { //this equals to the column in each row.
Matrix_sum[i][j]=Matrix_1[i][j]+Matrix_2[i][j];
}
printf("\n");
}
printf("The sum of Matrix_1 + Matrix_2 is \n");
for (int i = 0; i < Row; i++) { //this equals to the row in our matrix.
for (int j = 0; j < Column; j++) { //this equals to the column in each row.
printf("%d ",Matrix_sum[i][j]);
}
printf("\n");
}
}