Hỏi về return 0 và getch()

Vậy bạn tham khảo hàm getf() của mình. :slight_smile:

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

double getf(void) {
    char c = 0, sign = 1;
    double res1 = 0, res2 = 0;
    for (int first = 1; c = getch();) {
        if (first && c == '-') {
            sign = -sign;
            continue;
        } else first = 0;
        if (c == '.') break;
        if (!isdigit(c)) return res1 * sign;
        res1 = 10 * res1 + c - '0';
    }
    
    if (c != '.') return res1;

    for (double tenpow = 10;; tenpow *= 10) {
        c = getch();
        if (!isdigit(c)) return (res1 + res2) * sign;
        res2 += (double)(c - '0') / tenpow;
    }
}

int main() {
    double a = getf();
    printf("%g\n", a);
    return 0;
}