HDU - 1012ACM

这题就更简单了。

不说了~ 上个代码就好了。

//
//  main.cpp
//  uCalculatee
//
//  Created by Alps on 14/12/25.
//  Copyright (c) 2014年 chen. All rights reserved.
//

#include <iostream>
using namespace std;

double jiecheng(double b){
    double a = 1;
    while (b > 0) {
        a = a * b;
        b -= 1;
    }
    return a;
}

int main(int argc, const char * argv[]) {
    double a = 1,b = 1;
    int i;
    printf("n e\n");
    printf("- -----------\n");
    printf("0 1\n");
    for (i = 1; i <= 1; i++) {
        a = a + (1/jiecheng(b));
        printf("%d %.0f\n",i,a);
        b += 1;
    }
    for (; i <= 2; i++) {
        a = a + (1/jiecheng(b));
        printf("%d %.1f\n",i,a);
        b += 1;
    }
    for (; i <= 9; i++) {
        a = a + (1/jiecheng(b));
        printf("%d %.9f\n",i,a);
        b += 1;
    }
    return 0;
}


你可能感兴趣的:(HDU,1012)