-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.c
More file actions
82 lines (82 loc) · 1.76 KB
/
Array.c
File metadata and controls
82 lines (82 loc) · 1.76 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
#include <stdio.h>
void main()
{
int n,i,ch=0;
printf("Enter no. of elements in the array and then enter those numbers\n");
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++)
{ printf("%d:",i+1);
scanf("%d,",&arr[i]);
}
while(ch!=6)
{
printf("Enter your choice \n");
printf(" 1 - The sum of all elements \n 2 - The largest element \n 3 - The smallest element \n");
printf(" 4 - The average of all elements\n 5 - Display the array in reverse order\n 6 - Exit\n");
scanf("%d",&ch);
if(ch==1)
{
int sum=0;
for(i=0;i<n;i++)
{
sum=sum+arr[i];
}
printf("The sum of all the elements is %d \n",sum);
}
else if(ch==2)
{
int max=arr[0];
for(i=0;i<n;i++)
{
if(max<arr[i])
{
max=arr[i];
}
}
printf("The maximum among all the elements is %d \n",max);
}
else if(ch==3)
{
int min=arr[0];
for(i=0;i<n;i++)
{
if(min>arr[i])
{
min=arr[i];
}
}
printf("The minimum among all the elements is %d \n",min);
}
else if(ch==4)
{
float avg;
float sum=0;
for(i=0;i<n;i++)
{
sum=sum+arr[i];
}
avg=sum/n;
printf("The average of all the elements is %f \n",avg);
}
else if(ch==5)
{
int rev[n];
for(i=0;i<n;i++)
{
rev[n-i-1]=arr[i];
}
for(i=0;i<n;i++)
{
printf("%d ",rev[i]);
}
printf("\n");
}
else if(ch==6);
else
{
printf("Enter valid choice \n");
}
}
printf("Thankyou for using the array calculator");
}