-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27.c
76 lines (70 loc) · 1.53 KB
/
27.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
#include<stdio.h>
int main()
{
int arr[4][3];
int value;
int max(int arr[][3]);
int min(int arr[][3]);
int avg(int arr[][3]);
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
printf("Enter a value between -10 and 10 for matrix[%d][%d]:\n ", i+1, j+1);
scanf("%d", &value);
while (value <= -10 || value >= 10)
{
printf("Invalid input! Value must be between -10 and 10. Please try again:\n ");
printf("Enter a value between -10 and 10 for matrix[%d][%d]:\n ", i+1, j+1);
scanf("%d", &value);
}
arr[i][j] = value;
}
}
int maxium=max(arr);
int minium=min(arr);
int average=avg(arr);
printf("max=%d\n",maxium);
printf("min=%d\n",minium);
printf("avg=%d\n",average);
return 0;
}
int max(int arr[][3])
{
int max=arr[0][0];
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
if(arr[i][j]>max)
max=arr[i][j];
}
}
return max;
}
int min(int arr[][3])
{
int min=arr[0][0];
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
if(arr[i][j]<min)
min=arr[i][j];
}
}
return min;
}
int avg(int arr[][3])
{
int sum=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
sum+=arr[i][j];
}
}
int avg=sum/12;
return avg;
}