Yamada Stust OJ problem B: Write function: String to Double (II) (Append Code)

Source: Internet
Author: User

There is nothing wrong with this problem, my mistake is that I can't read the question.

Another thing to note is that floating-point numbers exist-0

1#include <stdio.h>2#include <ctype.h>3#include <math.h>4 #defineMax_str_len 10 + 55 DoubleStrtodouble (Charstr[]) {6     intState=0;7     DoubleSUM1 =0.0;8     Doublesum2 =0.0;9     intk=1;Ten     intDigited=0; One     intfuhao=1; A     if(!str[0])return 0; -      for(intI=0; str[i];i++){ -         if(digited==0&&str[i]=='-') the         { -Digited=1; -Fuhao =-1; -         } +         if(digited==0&&str[i]=='+'){ -Digited=1; +Fuhao =1;  A         } at         if(IsDigit (Str[i])) { -Digited=1; -             if(!state) sum1=Ten*sum1 +str[i]-'0'; -             Elsesum2+= (POW (0.1, k++)) * (str[i]-'0'); -         } -         Else if(str[i]=='.'){ inDigited=1; -State=1; to         } +     } -     returnfuhao* (sum1 +sum2); the } *   $ intMain ()Panax Notoginseng { -     CharS[max_str_len]; the      while(Gets (s)! =NULL) +printf"%lg\n", strtodouble (s)); A     return 0; the}

Yamada Stust OJ problem B: Write function: String to Double (II) (Append Code)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.