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; }
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.
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
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;
.
#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.
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!