Skip to content

Commit ad943dc

Browse files
Merge pull request #8 from Akshat2024/code
Matrix Sum and Difference in C
2 parents 67e4532 + 2e5d7d7 commit ad943dc

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

Matrix.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include<stdio.h>
2+
#include <conio.h>
3+
int main(){
4+
int a[10][10],b[10][10],c[10][10],d[10][10], row, col,i,j;
5+
6+
printf("Enter the rows number of both matrices\n");
7+
scanf("%d",&row);
8+
printf("Enter the columns number of both matrices\n");
9+
scanf("%d",&col);
10+
11+
12+
printf("Enter the elements of matrix A\n");
13+
for(i=0;i<row;i++){
14+
for(j = 0;j < col;j++){
15+
printf("Enter the element at [%d%d] : ",i,j);
16+
scanf("%d",&a[i][j]);
17+
}
18+
printf("\n");
19+
20+
}
21+
22+
printf("Enter the elements of matrix B\n");
23+
for(i=0;i<row;i++){
24+
for(j = 0;j < col;j++){
25+
printf("Enter the element at [%d%d] : ",i,j);
26+
scanf("%d",&b[i][j]);
27+
}
28+
printf("\n");
29+
30+
}
31+
32+
printf("The addition of A and B is \n\t\t");
33+
for(i=0;i<row;i++){
34+
for(j = 0;j < col;j++){
35+
c[i][j]=a[i][j] + b[i][j];
36+
}
37+
}
38+
//printing addition
39+
for(i=0;i<row;i++){
40+
for(j = 0;j < col;j++){
41+
printf(" %d ",c[i][j]);
42+
}
43+
printf("\n\t\t");
44+
}
45+
46+
47+
printf("\nThe subtraction of A and B is \n\t\t");
48+
for(i=0;i<row;i++){
49+
for(j = 0;j < col;j++){
50+
d[i][j]=a[i][j] - b[i][j];
51+
}
52+
}
53+
54+
//printing subtraction
55+
for(i=0;i<row;i++){
56+
for(j = 0;j < col;j++){
57+
printf(" %d ",d[i][j]);
58+
}
59+
printf("\n\t\t");
60+
}
61+
62+
63+
64+
return 0;
65+
}

binarySearch.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <stdio.h>
2+
#include <conio.h>
3+
int main()
4+
{
5+
int n, key,l,h,mid,x;
6+
printf("Enter the size of Array");
7+
scanf("%d", &n);
8+
int a[n];
9+
printf("Enter the key");
10+
scanf("%d", &key);
11+
printf("Enter the elements of Array");
12+
for (int i = 0; i < n; i++)
13+
{
14+
scanf("%d", &a[i]);
15+
}
16+
l = 0;
17+
h = n - 1;
18+
mid = ((l + h)/2);
19+
x=mid;
20+
while (l <= h)
21+
{
22+
if (key == a[x])
23+
{
24+
printf("position of the key in array\n");
25+
printf("%d",x);
26+
break;
27+
}
28+
if (a[x] > key)
29+
{
30+
h = x - 1;
31+
}
32+
if (a[x] < key)
33+
{
34+
l = x + 1;
35+
}
36+
}
37+
return 0;
38+
}

0 commit comments

Comments
 (0)