-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.c
50 lines (45 loc) · 801 Bytes
/
array.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
#include<0stdio.h>
int main(){
int n;
printf("enter array size:");
scanf("%d",&n);
int a[n];
int i;
printf("enter the elements of array");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int max=a[0], min=a[0], sum=0;
for(i=1;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
printf("\nmax is %d",max);
for(i=1;i<n;i++){
if(a[i]<min)
{
min=a[i];
}
}
printf("\nmin is %d",min);
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf("\nsum of array elements is %d",sum);
float avg=(float)sum/n;
printf("avg is %f",avg);
return 0;
}
------------------------------------------
output:
enter array size:3
enter array elements: 2 4 5
max is 5
min is 2
sum of array elements is 11
avg is 3.666667