Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a C programme by using visual Studio: a) Write a function with paramete

ID: 3804487 • Letter: 1

Question

1. Write a C programme by using visual Studio:

a) Write a function with parameters that returen the largest of three integer arguments. So users could call your function (name: max3) to output the maximum of three input values.

b) Make a function outside of the main routine. And in the main routine, please call this function and print the harmonic mean.

The harmonic mean of two numbers is obtained by taking the inverses of the two numbers, averaging them, and taking the inverse of the result. Write a function that takes two double arguments and returns the harmonic mean of the two numbers. In the main routine, call the function and print the mean.

- You may use this equation " 2*X*Y*(X+Y) "

c) Write a program to keep track of how many points a NBA player (e.g., Kobe Bryant) scored in each of 10 NBA basketball games. The frist six scores are entered when the array is initialized (int gameScore [10]={12, 5, 21, 15, 32, 10};), and then you are asked to input the player's scores for games 7~10 (Score are 21, 8, 11, and 14). After all the data is entered, the program loops through the 10 scores to compute average points per game.

Explanation / Answer

C code:

#include <stdio.h>

float HM(float a, float b)
{
   return ( 2.0/( (1/a) + (1/b) ) );
}

int max3(int a,int b,int c)
{
   int maxx = a;
   if(b > maxx)
   {
       maxx = b;
   }
   if(c > maxx)
   {
       maxx = c;
   }
   return maxx;
}

float Average(float *arr)
{
   float sum = 0;
   for (int i = 0; i < 10; ++i)
   {
       sum = sum + arr[i];
   }
   return sum/10.0;
}

int main()
{

   int a = 4;
   int b = 9;
   int c = 3;
   printf("Maximum of 3 numbers( %i , %i , %i ) is %i ", a,b,c, max3(a,b,c));  

   float a1 = 4.0;
   float b1 = 9.0;
   printf("Harmonic mean of numbers( %f , %f ) is %f ", a1,b1, HM(a1,b1) );  

   float gameScore[10] = {12, 5, 21, 15, 32, 10};

   for (int i = 7; i < 11; ++i)
   {
       printf("%s %i ", "Enter score of game", i);
       scanf("%f",&gameScore[i-1]);
   }
   printf("Average Score = %f ", Average(gameScore));
   return 0;
}

Sample Output:

Maximum of 3 numbers( 4 , 9 , 3 ) is 9
Harmonic mean of numbers( 4.000000 , 9.000000 ) is 5.538462
Enter score of game 7
10
Enter score of game 8
1
Enter score of game 9
1
Enter score of game 10
1
Average Score = 10.800000

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote