-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1054.cpp
More file actions
41 lines (37 loc) · 700 Bytes
/
1054.cpp
File metadata and controls
41 lines (37 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
#include<string.h>
#include<cstdio>
using namespace std;
int main(){
int n;
cin>>n;
char a[50],b[50];
double temp,sum=0;
int c=0;
for(int i=0;i<n;i++){
scanf("%s",a);
sscanf(a,"%lf",&temp);
sprintf(b,"%.2lf",temp);
int flag = 0;
for(int j=0;j<strlen(a);j++){
if(a[j]!=b[j])
flag = 1;
}
if(flag || temp<-1000||temp>1000)
{
printf("ERROR: %s is not a legal number\n",a);
continue;
}else{
c++;
sum +=temp;
}
}
if(c==1)
printf("The average of 1 number is %.2lf\n",sum);
else if(c>1)
printf("The average of %d numbers is %.2lf\n",c,sum/c);
else
printf("The average of 0 numbers is Undefined\n");
system("pause");
return 0;
}