Code:
#include <stdio.h>
#include <conio.h>
void main (void) {
float getint (void);
float a;
printf ("Data:- ");
a=getint();
printf ("\nNumber is %f",a);
}
float getint(void) {
char ch;
float n=0, dec=0, total;
int xcount=0, i;
ch=getchar();
while (!isdigit(ch) && ch!='.') ch=getchar();
while (isdigit(ch)) {
n=(n*10)+(ch-'0');
ch=getchar();
}
if (ch=='.') {
ch=getchar();
while (isdigit(ch)) {
xcount++;
dec=(dec*10)+(ch-'0');
ch=getchar();}
for (i=1; i<=xcount; i++) dec=dec*0.1;
}
total=n+dec;
return total;
}
but I think something is wrong with the floating point precision calculation...
Data:- 52.36
Number is 52.360001
I don't see anything wrong though, cause the char 52 gives 52 and the char .2 gives .2