-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayFunction.c
More file actions
56 lines (53 loc) · 1.62 KB
/
Copy pathArrayFunction.c
File metadata and controls
56 lines (53 loc) · 1.62 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
/*-------------------------------------------------------------------------------------------------------------------
ArrayFunction.c
Program to input numbers in an array, print contents of an array and find the average of the contents of the array
DIVYA RAJ.K
16-10-18
---------------------------------------------------------------------------------------------------------------------*/
#include<stdio.h>
//----------------------------------prototype---------------------------------------------
void fnInputArray(int N,int A[30]);
void fnPrintArray(int N,int A[30]);
float fnAvg(int N,int A[30]);
main()
{
int X[30],N;
float Avg;
system("clear");
printf("Program to input numbers in an array, print contents of an array and find the average of the contents of the array\n");
printf("Enter the number of elements in the array: ");
scanf("%d",&N);
printf("Enter the elements of the array:\n");
fnInputArray(N,X);
printf("\nThe elements of the array are:\n");
fnPrintArray(N,X);
Avg=fnAvg(N,X);
printf("\nThe average of %d elements are %.2f",N,Avg);
}
//----------------------------------fnInputArray---------------------------------------------
void fnInputArray(int N,int A[30])
{
int i;
for(i=1;i<=N;i++){
scanf("%d",&A[i]);
}
}
//----------------------------------fnPrintArray---------------------------------------------
void fnPrintArray(int N,int A[30])
{
int i;
for(i=1;i<=N;i++){
printf("%d\t",A[i]);
}
}
//----------------------------------fnAvg---------------------------------------------
float fnAvg(int N,int A[30])
{
int i,Sum=0;
float Avg;
for(i=1;i<=N;i++){
Sum=Sum+A[i];
}
Avg=(float)Sum/N;
return Avg;
}