Embed presentation
Download to read offline
![Write a C program Write functions that return the following values. (Assume that a and n are
parameters, where a is an array of int values and n is the length of the array.) (a) The largest
element in a. (b) The average of all elements in a. (c) The number of positive elements in a.
Solution
#include
#include
int largest(int* ,int );
float avg(int*,int);
int positive(int*,int);
int main()
{
int n,i=0,lar,count;
float average;
printf("Enter the number of elements in the array ");
scanf("%d",&n);
int a[n];
for(i=0;i0)
{
count+=1;
}
}
return count;
}](https://image.slidesharecdn.com/writeacprogramwritefunctionsthatreturnthefollowingvalues-230704163458-4a21f430/75/Write-a-C-program-Write-functions-that-return-the-following-values-pdf-1-2048.jpg)
The document describes a C program that includes functions for returning the largest element in an array, calculating the average of array elements, and counting positive elements. It outlines the function prototypes and presents a main function where user input determines the size of the array and gathers the elements. The program ultimately processes the input to compute the requested values.
![Write a C program Write functions that return the following values. (Assume that a and n are
parameters, where a is an array of int values and n is the length of the array.) (a) The largest
element in a. (b) The average of all elements in a. (c) The number of positive elements in a.
Solution
#include
#include
int largest(int* ,int );
float avg(int*,int);
int positive(int*,int);
int main()
{
int n,i=0,lar,count;
float average;
printf("Enter the number of elements in the array ");
scanf("%d",&n);
int a[n];
for(i=0;i0)
{
count+=1;
}
}
return count;
}](https://image.slidesharecdn.com/writeacprogramwritefunctionsthatreturnthefollowingvalues-230704163458-4a21f430/75/Write-a-C-program-Write-functions-that-return-the-following-values-pdf-1-2048.jpg)