Question
Write a C program to read a counter, and then, read real numbers based on the value of counter (the number must range from 0.0 to 100.0). Keep all the number entered into an array, and find the biggest, smallest and the middle number. Use void find_biggest_smallest() function to receive the array, and return biggest and smallest number. Let say biggest and smallest is 14 and 2. Therefore average = (14+2)/2 = 8.
The middle number is the number which is nearest to the average. For example, middle number is 8, the number before and after the number is 7 and 6. Since (average-6) and (7-average) yield same value, therefore, the middle number is 7 taking the nearest after the average. Use float find_middle() function to find the middle number.
Your main program should read the counter and store the number entered into an array, call the find_biggest_smallest(), find_middle() function, lastly display the biggest, smallest and middle number on the monitor.

dont have to excute just write the coding asap please need asap i only have 15 mins


Please enter number 1 (from 0 to 100) = 14.0 Please enter number 2 (from 0 to 100) 5.0 Please enter number 3 (from 0 to 100)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <stdio.h>
#include<math.h>

//function to return the biggest and smallest number
void find_biggest_smallest(float a[], int n, float *biggest, float *smallest)
{
int i;
*biggest = *smallest = a[0];
for(i=1; i<10; i++)
{
if(a[i] > *biggest) *biggest = a[i];
if(a[i] < *smallest) *smallest = a[i];
}
}

//function to return the middle number
float find_middle(float a[], int n)
{
int i;
float sum = 0;
for(i=0; i<n; i++)
{
sum += a[i];
}
float average = sum/n;

float middle = a[0];
for(i=1; i<10; i++)
{
if(fabs(average-a[i]) < fabs(average-middle))
middle = a[i];
}
return middle;
}

//main function
int main ()
{
//variable declaration
float arr[10], biggest, smallest;
int i, n;

//prompt and read value of counter
printf("Please enter value of counter: ");
scanf("%d", &n);
//prompt and read the numbers
for(i=0; i<n; i++)
{
printf("Please enter number %d (from 0 to 100) = ", i+1);
scanf("%f",&arr[i]);
}
//find the biggest and smallest number
find_biggest_smallest(arr, n, &biggest, &smallest);
//find the middle number
float middle = find_middle(arr, n);
  
//print biggest, smallest and middle number
printf("\n\nThe biggest number = %f", biggest);
printf("\nThe smallest number = %f", smallest);
printf("\nThe middle number = %f", middle);
}

Output:

Please enter value of counter: 10
Please enter number 1 (from 0 to 100) = 14.0
Please enter number 2 (from 0 to 100) = 5.0
Please enter number 3 (from 0 to 100) = 7.0
Please enter number 4 (from 0 to 100) = 2.0
Please enter number 5 (from 0 to 100) = 6.0
Please enter number 6 (from 0 to 100) = 8.0
Please enter number 7 (from 0 to 100) = 12.0
Please enter number 8 (from 0 to 100) = 9.0
Please enter number 9 (from 0 to 100) = 3.0
Please enter number 10 (from 0 to 100) = 4.0


The biggest number = 14.000000
The smallest number = 2.000000
The middle number = 7.000000

Note Whether you face any problem or need any modification then share with me in the comment section, I'll happy to help you. Remember there are some mistakes in the question. Average calculation and middle calculation have some mistakes.

Add a comment
Know the answer?
Add Answer to:
Write a C program to read a counter, and then, read real numbers based on the...
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
  • This program is in C++ Write a program that validates charge account numbers read in from...

    This program is in C++ Write a program that validates charge account numbers read in from the file Charges.txt following this assignment (A23 Data). Use a selection sort function on the array to sort the numbers then use a binary search to validate the account numbers. Print out the sorted list of account numbers so you can see the valid ones. Prompt the user to enter an account number and the validate that number. If the account number entered is...

  • this program is in C. Write a program that computes the number of elements in an...

    this program is in C. Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2,2,4}). Sample execution of the program for this array...

  • WRITE A PROGRAM IN C THAT DOES THE FOLLOWING: The numbers are real numbers, read in...

    WRITE A PROGRAM IN C THAT DOES THE FOLLOWING: The numbers are real numbers, read in as double precision floating-point numbers, one number perline, possibly with some white space before or after. Hint: use scanf. There are guaranteed to be no more than one million (that’s 10^6) numbers in the input, and no fewer than two legitimate numbers. Any number that is equal to zero should be ignored (discarded, not stored in the array or counted in any way).

  • Write a program that lets the user enter 10 values into an array. The program should...

    Write a program that lets the user enter 10 values into an array. The program should then display the largest and the smallest values stored in the array. The program should display the following message to the user at the beginning "This program will ask you to enter ten values. Then it will determine the largest and smallest of the values you entered.Please enter 10 integers separated by spaces: " And then after user entered the numbers, it should display...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers...

    c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...

  • In C++ This program will read a group of positive numbers from three files ( not...

    In C++ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the scores in the order that they were input, showing each number and what percentage it is above or below the average for each file. Note: Finding the average doesn’t require an array. Finding...

  • Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel –...

    Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel – sentinel is used to indicate the end of input and must not to be considered as the valid data for the computation). Perform the following operations for the integers entered by the user. Display the sum of the numbers less than 100 Display the smallest of the positive integers Display the largest of the negative integers Display how many integers are between 100 and...

  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • In c++ programming, can you please edit this program to meet these requirements: The program that...

    In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; }    while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...

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