Question

This assignment should be relatively easy. Write a program in C language, that reads in numbers...

This assignment should be relatively easy. Write a program in C language, that reads in numbers from any file, one per line, until it detects that a 0 (zero not an oh') has been entered The 0 does not count as part of the number series. After all numbers have been entered print out the number of items entered, the sum, the minimum value entered, the maximum value entered, and the arithmetic mean (one on each line), in the order listed here.

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

#include<stdio.h>
#include<limits.h>
void main()
{
//declare file pointer
FILE *fp;
//declare count for counting numbers present in file till 0 is encountered
int count=0;
//declare min and max for getting minimum and maximum number from file
int min=INT_MAX,max=0;
//declare sum and mean for calculating mean of numbers
int sum=0;
float mean=0.0;
//declare number
int number;
//open file for reading
fp=fopen("numbers.txt","r");
//read the number from file
fscanf(fp,"%d",&number);
//read numbers line by line till 0 is encountered
while(number!=0)
{
++count;
if(min>number)
min=number;
if(max<number)
max=number;
sum+=number;
//read next number from file
fscanf(fp,"%d",&number);
}
printf("Number of items = %d\n",count);
printf("Sum = %d\n",sum);
printf("Minimum = %d\n",min);
printf("Maximum = %d\n",max);
printf("Mean = %f\n",(float)sum/count);
}

Output

Add a comment
Know the answer?
Add Answer to:
This assignment should be relatively easy. Write a program in C language, that reads in numbers...
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 assignment should be relatively easy. Write a program in any reasonably high-level language, that reads...

    This assignment should be relatively easy. Write a program in any reasonably high-level language, that reads in numbers from a file, one per line, until it detects that a 0 (zero not an oh') has been entered The 0 does not count as part of the number series. After all numbers have been entered print out the number of items entered, the sum, the minimum value entered, the maximum value entered, and the arithmetic mean (one on each line), in...

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • Assignment #9 will be the construction of a program that reads in a sequence of integers...

    Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers. Then compute the minimum number, compute the largest number among the numbers that are divisible by 2, count even numbers, and compute the...

  • Write a C language program that will prompt for 12 different resistor values, entered one at...

    Write a C language program that will prompt for 12 different resistor values, entered one at a time via the keyboard, expressed in Ohms. Valid values are 0.01 Ohm up to 10,000,000,000 Ohms. Write each entry to a text file on the disk thus: Resistor 1 Ohmic value = 2200. Update the resistor number for each of the 12 entries. Do not repeat any resistance value. Write a second C language program to read the 12 entries from the text...

  • Easy 68k code - assembly language Write a 68K program that reads two integers (>10 and...

    Easy 68k code - assembly language Write a 68K program that reads two integers (>10 and <225) of the keyboard, adds them together and multiplies them, writes the numbers and the results of addition and multiplication on the screen. If the numbers are not on the range, writes an error message and requests a new number. Example of the execution: Insert the first number: 10 Insert the second number:15 The sum is: 25 The product is: 150 Please take a...

  • Please write in Python language. Assignment 5 0 Write a program that reads in integers and...

    Please write in Python language. Assignment 5 0 Write a program that reads in integers and then determines whether input value is prime number or not(using for statement) • First input Input number: 18457 yes . Second input Input number: 52 no

  • (Count positive and negative numbers and compute the average of numbers) Write a program that reads...

    (Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.' *So I think my code is looping because the...

  • Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

    Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...

  • Could anyone please help with this Python code assignment? In this programming assignment you are to...

    Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...

  • C++ PROGRAMING Write a program that reads numbers from the input stream until a zero is...

    C++ PROGRAMING Write a program that reads numbers from the input stream until a zero is encountered. Display the average (rounded down to an integer), the maximum number and the minimum number. Assume that numbers entered will be between 1 and 1000. For example: Enter a number: 33 Enter a number: 88 Enter a number: 77 Enter a number: 22 Enter a number: 66 Enter a number: 55 Enter a number: 0 Average: 56 Max: 88 Min: 22 Another example:...

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