File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ //Matrix will be a two dimensional array and must be passed to a functions
2+ by using pointers .
3+
4+ #include <stdio.h>
5+ void AddMatrix (int (* a )[100 ],int (* b )[100 ],int r1 ,int c1 )
6+ {
7+ int i ,j ;
8+ for (i = 0 ;i < r1 ;i ++ )
9+ {
10+ for (j = 0 ;j < c1 ;j ++ )
11+ {
12+ * (* (a + i )+ j )= * (* (a + i )+ j )+ * (* (b + i )+ j );
13+ }
14+ }
15+ }
16+
17+ int main ()
18+ {
19+ int A [100 ][100 ],B [100 ][100 ];
20+ int i ,j ,r1 ,r2 ,c1 ,c2 ;
21+ printf ("Enter the row of 1st matrix " );
22+ scanf ("%d" ,& r1 );
23+ printf ("Enter the column of 1st matrix " );
24+ scanf ("%d" ,& c1 );
25+ for (i = 0 ;i < r1 ;i ++ )
26+ {
27+ for (j = 0 ;j < c1 ;j ++ )
28+ {
29+ printf ("Enter the number " );
30+ scanf ("%d" ,& A [i ][j ]);
31+ }
32+ }
33+ printf ("Enter the row of 2nd matrix " );
34+ scanf ("%d" ,& r2 );
35+ printf ("Enter the column of 2nd matrix " );
36+ scanf ("%d" ,& c2 );
37+ for (i = 0 ;i < r2 ;i ++ )
38+ {
39+ for (j = 0 ;j < c2 ;j ++ )
40+ {
41+ printf ("Enter the number " );
42+ scanf ("%d" ,& B [i ][j ]);
43+ }
44+ }
45+ if (r1 == r2 && c1 == c2 )
46+ {
47+ AddMatrix (A ,B ,r1 ,c1 );
48+ printf ("After addition :\n" );
49+ for (i = 0 ;i < r2 ;i ++ )
50+ {
51+ for (j = 0 ;j < c2 ;j ++ )
52+ {
53+ printf ("%d " ,A [i ][j ]);
54+ }
55+ printf ("\n" );
56+ }
57+ }
58+ else
59+ {
60+ printf ("Matrix addition not possible." );
61+ }
62+ return 0 ;
63+ }
You can’t perform that action at this time.
0 commit comments