Advertisement
AJTAMjid2000

Untitled

Jul 3rd, 2021
1,170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<ctype.h>
  3. #include<string.h>
  4. #define MAXLINE 100
  5.  
  6. int getline1(char s[], int lim)
  7. {
  8.     int i=0,c;
  9.  
  10.     while(--lim>0 && (c=getchar())!=EOF && c!='\n')
  11.     {
  12.         s[i++]=c;
  13.  
  14.     }
  15.     if(c=='\n')
  16.     {
  17.         s[i++]=c;
  18.     }
  19.     s[i]='\0';
  20.  
  21.     return i;
  22. }
  23.  
  24. int main()
  25. {
  26.       double sum, atop(char [] );
  27.       char line [MAXLINE];
  28.       int getline1(char line [], int max);
  29.  
  30.  
  31.       sum=0.0;
  32.    while(getline1(line , MAXLINE)>0)
  33.      {
  34.           sum=atop(line);                                  //234.67
  35.           printf("Scientific form  of the given string  ---->>>    %g\n",sum);
  36.           sum=0;
  37.  
  38.       }
  39.  
  40.       return 0;
  41.  
  42. }
  43. double atop(char s [])
  44. {
  45.     double value ,power;
  46.  
  47.     int i=0,sign;
  48.     for(i=0;isspace(s[i]);i++)//skip white space
  49.     {
  50.         ;
  51.     }
  52.     sign =   (s[i]=='-')? -1: 1;   //-23.67// 23*10+6=236*10+7=2367/100
  53.     if(s[i]=='+' || s[i]=='-')
  54.     {
  55.         i++;
  56.     }
  57.     for(value=0.0; isdigit(s[i]); i++)
  58.     {
  59.         value=10.0 *value+(s[i]-'0');
  60.     }
  61.     if(s[i]=='.')
  62.     {
  63.         i++;
  64.     }
  65.     for(power=1.0; isdigit(s[i]); i++)
  66.     {
  67.         value=10.0 *value+(s[i]-'0');
  68.         power*=10.00;
  69.     }
  70.  
  71.  
  72.  
  73.         return sign*(value/power);
  74. }
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement