Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<ctype.h>
- #include<string.h>
- #define MAXLINE 100
- int getline1(char s[], int lim)
- {
- int i=0,c;
- while(--lim>0 && (c=getchar())!=EOF && c!='\n')
- {
- s[i++]=c;
- }
- if(c=='\n')
- {
- s[i++]=c;
- }
- s[i]='\0';
- return i;
- }
- int main()
- {
- double sum, atop(char [] );
- char line [MAXLINE];
- int getline1(char line [], int max);
- sum=0.0;
- while(getline1(line , MAXLINE)>0)
- {
- sum=atop(line); //234.67
- printf("Scientific form of the given string ---->>> %g\n",sum);
- sum=0;
- }
- return 0;
- }
- double atop(char s [])
- {
- double value ,power;
- int i=0,sign;
- for(i=0;isspace(s[i]);i++)//skip white space
- {
- ;
- }
- sign = (s[i]=='-')? -1: 1; //-23.67// 23*10+6=236*10+7=2367/100
- if(s[i]=='+' || s[i]=='-')
- {
- i++;
- }
- for(value=0.0; isdigit(s[i]); i++)
- {
- value=10.0 *value+(s[i]-'0');
- }
- if(s[i]=='.')
- {
- i++;
- }
- for(power=1.0; isdigit(s[i]); i++)
- {
- value=10.0 *value+(s[i]-'0');
- power*=10.00;
- }
- return sign*(value/power);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement