-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path170_2D_Array.c
More file actions
103 lines (84 loc) · 1.7 KB
/
Copy path170_2D_Array.c
File metadata and controls
103 lines (84 loc) · 1.7 KB
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
#include<stdio.h>
void insert(int x[100][100],int m,int n)
{
printf("\n Enter Values for the Matrix \n");
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&x[i][j]);
}
}
}
void display(int x[100][100],int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",x[i][j]);
}
printf("\n\n");
}
}
void sum(int x[100][100],int m,int n)
{
int i,j,s=0,b[m*n],k=0,temp;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[k++]=x[i][j];
if(i==0 || i==m-1 || j==0 || j==n-1)
s=s+x[i][j];
}
}
printf("\n Unsorted Boundary Sum %d\n",s);
for(i=0;i<k-1;i++)
{
for(j=0;j<k-1-i;j++)
{
if(b[j]>b[j+1])
{
temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}
}
}
k=0;
s=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
x[i][j]=b[k++];
if(i==0 || i==m-1 || j==0 || j==n-1)
s=s+x[i][j];
printf("%d\t",x[i][j]);
}
printf("\n\n");
}
printf("\n sorted Boundary Sum %d",s);
}
int main()
{
int mat[100][100],m,n;
L1:
printf("\nEnter row Number ");
scanf("%d",&m);
if(m<1 || m>100)
goto L1;
L2:
printf("\nEnter col Number ");
scanf("%d",&n);
if(n<1 || n>100)
goto L2;
insert(mat,m,n);
printf("\n The 1st Matrix Is \n");
display(mat,m,n);
sum(mat,m,n);
return 0;
}