Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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\n", a,b,c, max3(a,b,c));  

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

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

   for (int i = 7; i < 11; ++i)
   {
       printf("%s %i\n", "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

Add a comment
Know the answer?
Add Answer to:
1. Write a C programme by using visual Studio: a) Write a function with parameters that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that contains a function called swapNums. This function takes two integer parameters,...

    Write a C++ program that contains a function called swapNums. This function takes two integer parameters, swaps them in memory, and outputs the results (there is nothing to return). In main, ask the user to enter two different numbers, output them as entered (step 1), call the function swapNums() which will output the numbers swapped (step 2), and then output the values again in main (step 3). You should have three sets of output. Sample run (10 and 5 were...

  • Positive and negative: Return these four results using C++ reference parameter Write a function, named sums(),...

    Positive and negative: Return these four results using C++ reference parameter Write a function, named sums(), that has two input parameters; an array of floats; and an integer, n, which is the number of values stored in the array. Compute the sum of the positive values in the array and the sum of the negative values. Also count the number of positives and negative numbers in each category. Write a main program that reads no more than 10 real numbers...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It...

    C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It generates a random number between 25 and 50 (not including 50). It then creates an array on the memory heap of that length. It generates a random high number (mine was between 5 and 10) and a random low number (between -5 and -10) and fills in the array iteratively with random numbers between the high and the low numbers*, and it returns that...

  • Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and...

    Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and print the transpose of a two- dimensional array. Within C program (the MAIN function); Declare a two- dimensional 3X2 integer array A and initialise with the values (1,2), (3,4), (5,6), declare also a two-dimensional 2X3 integer array B and initialise it with zero. Call the FUNCTION and pass arrays A and B to the FUNCTION as arguments. Print the array A and its transpose....

  • Done in C++ using visual studio 1. Write a program with one additional function called int[]...

    Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...

  • Write a Python program that asks the user to type in their three quiz scores (scores...

    Write a Python program that asks the user to type in their three quiz scores (scores between 0 and 100) and displays two averages. The program should be written so one function gets the user to input a score, another function takes the three scores and returns the average of them. And another function takes the three scores and averages the two highest scores (in other words, drops the lowest). Each of these functions should do the computation and return...

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

  • Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a...

    Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a correct and complete C++ program that inputs 20 integer values from the user and performs three calculations. In the main function, input the values from the user. As part of your answer, write a sub-function, named calcAvg (), which takes two arguments and returns the average of all the integers. Also write another sub-function, named reverseArray (), which takes two arguments and reverses the...

  • C++ this program will get two integers from the user. The program will 1. call getProduct...

    C++ this program will get two integers from the user. The program will 1. call getProduct (int, int, int &); where the first two arguments are the two input integers and third one is the product of these 2 integers. 2. call printEvenAscending (int, int); where the two arguments are the two input integers. This function will print all -even numbers between the two arguments in an ascending order. Note, the two input integers could be in any order (such...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT