4. Write a program with the following functions, a) void fillArray ( int x[], in
ID: 1863389 • Letter: 4
Question
4. Write a program with the following functions,
a) void fillArray(int x[],int size) : reads data and store it in an array.
b) void printArray (int x[],int size) : prints the array.
c) int largestElement( int x[],int size) : finds and returns max element in an Array.
d) int minimumElement(int x[],int size) : finds and returns minimum element in an Array.
e) int sumArray ( int x[],int size) : finds and returns the sum of an array.
f) float avgArray( int x[],int size) : finds the average of an Array. Call sumArray function to calculate sum. DO NOT REPEAT THE CODE TO FIND THE SUM.
g) void copyArray( int x[], int y[], int size) : copies array x into array y. Array y must be atleast as large as the array x.
Write main method to test all methods.
Explanation / Answer
void fillArray(int x[],intsize)
{
int i;
for(i=0;i<intsize;i++)
scanf("%d",i+n);
}
void printArray (int x[],intsize)
{
int i;
for(i=0;i<intsize;i++)
printf("%d",i[n]);
}
int largestElement( int x[],intsize)
{
int i,largest=x[0];
for(i=0;i<intsize;i++)
if(x[i]>largest) largest = x[i];
return largest;
}
int minimumElement(int x[],intsize)
{
int i,smallest=x[0];
for(i=0;i<intsize;i++)
if(x[i]<smallest) smallest = x[i];
return smallest;
}
int sumArray ( int x[],intsize)
{
int i,sum=0;
for(i=0;i<intsize;i++)
sum += x[i];
return sum;
}
float avgArray( int x[],intsize)
{
return sumArray(x,intsize)/intsize ;
}
void copyArray( int x[], int y[], intsize)
{
int i;
for(i=0;i<intsize;i++)
y[i]=x[i];
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.