Array (use of one-dimensional arrays)

Source: Internet
Author: User
Tags arrays float number

Use a one-dimensional array to calculate the average value of multiple numbers

Program conception: first define a floating-point number Group with a size of 20. When the program is running, first set the total data addition variable to 0 and input the data. If select statement to determine whether the input number exceeds 20. When the input is less than 20, execute the program in the data input loop, otherwise, the message "Please input a number less than 20" is output. The program function in the loop reads user input data and accumulates it into the Summary variable. The average value is the sum of data divided by the number of data.

Void main ()
{
Int max = 0;
Int I;
Float number [20];
Float summary;
Float average;
Summary = 0;
Printf ("Please input the number of data :");
Scanf ("% d", & max );
If (max <= 20)
    {
For (I = 0; I <max; I ++)
        {
Printf ("Please input a number :");
Scanf ("% f", & number [I]);
Summary + = number [I];
        }
Average = summary/max;
Printf ("The average is % 5.2fn", average );
    }
Else
Printf ("Please input a number less than 20 .");
}

Running result:
Please input the number of data: 5
Please input the number: 13.5
Please input the number: 170.4
Please input the number: 65.45
Please input the number: 84
Please input the number: 20
The average is 70.67

Use a one-dimensional array to design a simple employee salary management system (with query and modification functions)
Program conception:
First, an integer array with a size of 10 is set by default, and 10 employee salary data are set according to the employee number in advance.
A while loop provides a user menu for users to choose from. The first function is to query employee data, the second function is to modify employee data, and the third function is to end the system.
When the user selects 1 or 2, the user is required to enter the employee number before the program judges whether the input is the correct employee number. If The employee is correct, The employee's salary data is output. If The employee is incorrect, The employee's salary data is output. "# The error employee number! ". If the user selects 2, the user is further required to enter the modified new employee data and save the data back to the employee's salary data array.
Void main ()
{
Int employee [10] = {27000,32000, 32500,27500, 28500,29000,
31000,32500, 30000,26000}</

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.