2022级统计计算机双学位《程序设计原理与C语言》上机作业

1046. atof

单点时限: 2.0 sec

内存限制: 512 MB

Extend atof to handle scientific notation of the form 123.45e-6 where a floating-point number may be followed by e or E and an optionally signed exponent.

Write a program to enter a string and call atof.

See also Exercise 4-2 in the textbook.

#include <stdio.h>

/***************************************************************/
/*                                                             */
/*  DON'T MODIFY main function ANYWAY!                         */
/*                                                             */
/***************************************************************/

double atof(char s[]) {
    // TODO: your function definition
}

#define MAXLINE 80  /* maximum input line length */

int main() {
    char s[MAXLINE];
    scanf("%s", s);
    printf("%f\n", atof(s));
}

样例

Input
123.45e-6
Output
0.000123