#include <stdio.h>
int main(){
int A[5];
int sum=0;
for (int i=0;i<5;i++){
scanf("%d",&A[i]);
sum +=A[i];
}
double average=(double)sum/5;
printf("%.3f\n",average);
return 0;
}
This code reads 5 integers from the user, stores them in an array, calculates their sum, then computes and prints the average with 3 decimal places.
- The variable `sum` is an integer, so the division `sum/5` performs integer division before the cast to double. This truncates the fractional part. Consider how to ensure the division uses floating-point arithmetic.
- The array `A` is declared but never used after storing values. This is not an error, but you could simplify the code by removing the array if you only need the sum.