Searching maximal and minimal numbers

From CS100 Homework 1-1

题目描述

In this problem, you are required to write a C program to search for maximal and minimal values in a series of floating-point data. Here you would like to input n values. You can update some variables as you read in new values. Finally, you will output the minimal and maximal values of all your inputs. The following is a demo process for the program if you can do it successfully: (red indicates input)

image
问题输入

The first number is an integer n , which represent show many floating point numbers the user wants to input. The followingninputs aren floats with at most 1 decimal digit, which are the n numbers you want to calculate theminandmax.
Note that it is not certain how many inputs there are, so we recommend not using an array.

问题输出

First, your program should output a prompt"Please type number of inputs: "
Then, after the user inputnandn numbers.
Your program should output two lines.
The first line is"Max value: "and the maximum value of the inputs followed.
The second line is"Min value: ", and the minimum value of the inputs followed.
* All of your outputs should be printed with “printf” to only 1 decimal point digit floating point number, even if a number is an integer.
* The value of inputs are restricted to be between -10000.0 and 10000.0.
* (The quotation marks are not to be printed.)

样例输入1
5
3.2
1.6
7.8
8.3
5.1
样例输出1
Please type number of inputs: Max value: 8.3
Min value: 1.6




在线测试 (语言:C;时间限制:1s)
当前状态

无提交记录

有话想说?