WRITE IT IN C A. Write a function that takes an array of ints, and the size of t
ID: 3686034 • Letter: W
Question
WRITE IT IN C
A. Write a function that takes an array of ints, and the size of the array – another int.It also returns a double.Call this one ‘average.’Return a double that is the average of the values in the array.Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92}
B. Write a function that takes one double parameter, and returns a char.The parameter represents a grade, and the char represents the corresponding letter grade.If you pass in 90, the char returned will be ‘A’.If you pass in 58.67, the char returned will be an ‘F’ etc.Use the grading scheme on the syllabus for this course to decide what letter to return.
C. Write a function that takes 3 int arguments and returns the largest of the 3.
Explanation / Answer
Please find the required solution:
#include <stdio.h>
double average(int[],int);
char grade(double marks);
int max(int a,int b,int c);
int main()
{
int a[7]={78, 90, 56, 99, 88, 68, 92};
printf("average=%lf ",average(a,7));
printf("max value=%d ",max(110,55,666));
printf("grade=%c ",grade(90));
return 0;
}
double average(int num[],int length)
{
int i=0,sum=0;
for(;i<length;i++)
{
sum+=num[i];
}
return (double)sum/length;
}
int max(int a,int b,int c)
{
int max=a;
if(max<b)
{
if(b<c)
{
max=c;
}
else
{
max=b;
}
return max;
}
if(max<c)
{
max=c;
}
else
{
return max;
}
}
char grade(double marks)
{
if(marks==90)
return 'A';
else if(marks==58.67)
return 'F';
return ' ';
}
Sample output:
average=81.571429
max value=666
grade=A
average=81.571429
max value=666
grade=A
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.