How to find the average of five input numbers in C language?

coldplay.xixi
Release: 2020-06-22 16:16:19
Original
35170 people have browsed it

How to find the average of five input numbers in C language?

Recommended tutorial: "c Video Tutorial"

How to find the average of five numbers input in c language?

C language input five numbers to calculate the average method:

1. Step 1: Open our DEV C software and click "New Source" code".

2. Enter the following source code on the editing page:

#include <stdio.h>
int main( )
{
int *p;
int i,a[5];
float sum=0,average;
p=a;
printf("please input 5 numbers:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(p=a;p<(a+5);p++)
sum=sum+*p;
average=sum/5;
printf("average=%f",average);
return 0;
}
Copy after login

How to find the average of five input numbers in C language?

3. Because this program writing requires us to first define an integer array a[ 5], use the scanf statement to input each element in the array. So when writing source code, we must first write this requirement on the computer.

How to find the average of five input numbers in C language?

4. Because we are required to use pointers to access the numbers we enter, we must first give each number we enter its address, so that we can for a visit. Look at the picture below

How to find the average of five input numbers in C language?

5. Because the final result of the question requires us to input 5 integers from the keyboard, and finally the computer outputs the average value, so in the code we Must contain these two sets of codes

sum=sum+*p;
average=sum/5;
Copy after login

.

How to find the average of five input numbers in C language?

#6. After all the codes are written successfully, we click "Run", then enter any 5 integers in the pop-up input panel and press the Enter key to get out our average.

How to find the average of five input numbers in C language?

Recommended related courses: "c#.net Development Graphic Tutorial"

The above is the detailed content of How to find the average of five input numbers in C language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template