哪位大佬帮我看看为什么输入样例2 18 17输出的是 18

B2054 求平均年龄

KAI1119 @ 2024-11-14 19:40:04

#include<bits/stdc++.h>
using namespace std;
int a,b;
double cnt;
int main(){
  cin>>a;
  for(int i=1;i<=a;i++){
    cin>>b;
    cnt+=b;
  }
  printf("%2.lf",cnt/a);
  return 0;
}

by yangxikun @ 2024-11-14 19:43:42

@KAI1119

printf("%2.lf",cnt/a);
printf("%.2lf",cnt/a);

by KAI1119 @ 2024-11-14 19:53:41

谢谢


by kungeruyi @ 2024-11-14 20:35:50

不是

printf("%2.lf",cnt/a);

printf("%.2lf",cnt/a);

|