- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to calculate range of values and an average cost of a personal system.
Problem
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
Solution
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.
Example
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
"); 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("
"); printf("Total values : %d
", count); printf("Highest-value: %f
Lowest-value : %f
", high, low); printf("Range : %f
Average : %f
", range, average); }
Output
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
- Related Articles
- C++ Program to Calculate Average of Numbers Using Arrays
- C# Program to find the average of a sequence of numeric values
- MySQL query to calculate the average of values in a row?
- 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.
- Write a C program to calculate the average word length of a sentence using while loop
- Golang Program to Calculate the Average of Numbers in a Given List
- Java program to calculate the average of numbers in Java
- C++ Program to calculate Bitonicity of an Array
- Program for average of an array(Iterative and Recursive) in C++
- How to calculate cost of equity and market value of a firm?
- Calculate average of column values and display the result with no decimals in MySQL
- Calculate range of data types using C++
- Program to calculate area of Circumcircle of an Equilateral Triangle in C++
- C++ Program to Calculate Power of a Number

Advertisements