The average age of the digital summed ,,

average age

There were a number of students in the class, each student is given the age (integer), find the average age of all students in the class, with two decimal places.
code show as below
#include <stdio.h>
int main(){
int n,i,age[10000],sum=0;
float avg;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&age[i]);
sum+=age[i];
}
avg=sum/n;
printf("%.2f",avg);
}

Digital sum

Given a positive integer a, and an additional five positive integers, the question is: five integers, the integer and less than a What?
code show as below
#include <stdio.h>
int main(){
int a,i,sum=0;
int b[5];
scanf("%d",&a);
for(i=0;i<5;i++){
scanf("%d",&b[i]);
if(b[i]<a)
sum+=b[i];
}
printf("%d",sum);
}

Guess you like

Origin blog.csdn.net/m0_45128748/article/details/90997920