forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1125Floating Point Numbers.cpp
More file actions
68 lines (58 loc) · 1 KB
/
1125Floating Point Numbers.cpp
File metadata and controls
68 lines (58 loc) · 1 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#include<math.h>
int main(void){
char num[16];
double value;
int i,man,judge,count;
printf("Program 6 by team X\n");
while(gets(num)){
judge=count=0;
man=0;
value=1;
for(i=7;i>=1;i--)
man+=(num[i]-'0')*(int)pow(2,7-i);
if(man==0) judge=1;
man-=63;
for(i=8;i<16;i++)
value+=(num[i]-'0')*pow(2,7-i);
if(value==1&&judge==1){
printf(" 0.000000e+000\n");
continue;
}
if(num[0]=='1') printf("-");
else printf(" ");
if(man>0){
for(i=1;i<=man;i++){
value*=2;
if(value>=10){
value/=10;
count++;
}
}
}
else{
man*=-1;
for(i=1;i<=man;i++){
value/=2;
if(value<1){
value*=10;
count--;
}
}
}
printf("%.6fe",value);
if(count==0) printf("+000\n");
else{
if(count<0){
printf("-");
count*=-1;
}
else printf("+");
if(count<10) printf("00%d\n",count);
else if(count<100) printf("0%d\n",count);
else printf("%d\n",count);
}
}
printf("End of program 6 by team X\n");
return 0;
}