- Related Questions & Answers
- C++ Program to Calculate Average of Numbers Using Arrays
- Calculate weight average cost of capital of a company XYZ using below assumption data.
- Calculate weighted average cost of capital of a ABC ltd with the following data.
- MySQL query to calculate the average of values in a row?
- How to calculate cost of equity and market value of a firm?
- C# Program to find the average of a sequence of numeric values
- C++ Program to calculate Bitonicity of an Array
- Java program to calculate the average of numbers in Java
- Calculate range of data types using C++
- What is the importance and limitation of weighted average cost of capital?
- Calculate average of column values and display the result with no decimals in MySQL
- Program for average of an array(Iterative and Recursive) in C++
- Write a C program to calculate the average word length of a sentence using while loop
- What is weighted average cost of capital (WACC)?
- How to calculate cost of capital with tax rate?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

A personal system is sold at different costs by the vendors.

Let’s take the list of costs (in hundreds) quoted by some vendors −

25.00, 30.50, 15.00, 28.25, 58.15,

37.00, 16.65, 42.00 68.45, 53.50

Calculate the average cost and range of values.

The difference between the highest and the lowest values in the series is called range Hence, Range = highest value - lowest value.

Now, find the highest and the lowest values in the series.

Following is the C program to calculate the range of values and average cost of a personal system −

#include<stdio.h> main(){ int count; float value, high, low, sum, average, range; sum = 0; count = 0; printf("enter no's in line and at end press any negative number\n"); input: scanf("%f", &value); if (value < 0) goto output; count = count + 1; if (count == 1) high = low = value; else if (value > high) high = value; else if (value < low) low = value; sum = sum + value; goto input; output: average = sum/count; range = high - low; printf("\n\n"); printf("Total values : %d\n", count); printf("Highest-value: %f\nLowest-value : %f\n", high, low); printf("Range : %f\nAverage : %f\n", range, average); }

When the above program is executed, it produces the following output −

Enter numbers in line and at end press any negative number 22.4 56.8 12.3 48.6 31.4 19.0 -1 Total values: 6 Highest-value: 56.799999 Lowest-value: 12.300000 Range: 44.500000 Average: 31.750000

Advertisements