-
Notifications
You must be signed in to change notification settings - Fork 0
/
c10p12.c
85 lines (83 loc) · 2.11 KB
/
c10p12.c
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<stdio.h>
#include<math.h>
void strToFloat(char string[]);
int main(void)
{
strToFloat("-867.6921");
return 0;
}
void strToFloat(char string[])
{
int intValue=0,count=0;
int result=0,result2=0;
int i=0;
//for negative decimals
if(string[i]=='-')
{
i=1;
while(string[i]!='.')
{
if(string[i] >= '0' && string[i] <= '9')
{
intValue = '0'-string[i];
printf("intvalue = %i\n",intValue);
result = result * 10 + intValue;
printf("result = %i\n",result);
}
i++;
}
i=i+1;
while(string[i]!='\0')
{
if (string[i] >= '0' && string[i] <= '9')
{
intValue = '0'-string[i];
printf("intvalue = %i\n",intValue);
result2 = result2 * 10 + intValue;
printf("result = %i\n",result2);
count++;
}
i++;
}
printf("count = %i\n",count);
float result3;
result3=(float)result2*pow(0.1,(float)count);
printf("result 3 : %f\n",result3);
result3=result+result3;
printf("\n\nFloat : %.4f \n\n",result3);
}
//For positive decimals
else
{
while(string[i]!='.')
{
if(string[i] >= '0' && string[i] <= '9')
{
intValue = string[i] - '0';
printf("intvalue = %i\n",intValue);
result = result * 10 + intValue;
printf("result = %i\n",result);
++i;
}
}
i=i+1;
while(string[i]!='\0')
{
if(string[i] >= '0' && string[i] <= '9')
{
intValue = string[i] - '0';
printf("intvalue2 = %i\n",intValue);
result2 = result2 * 10 + intValue;
printf("result2 = %i\n",result);
count++;
}
i++;
}
printf("count = %i\n",count);
float result3;
result3=(float)result2*pow(0.1,(float)count);
printf("result 3 : %f\n",result3);
result3=result+result3;
printf("\n\nFloat : %.4f \n\n",result3);
}
}