
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 1.求1/阶乘累加
int main() {
    int n;
    int i;
    double temp = 1;
    double result = 0;
    printf("Input:");
    scanf("%d", &n);
    for (i = 1; i < n; i++) {
        temp *= i;//1,2,6,24
        result+=1/temp; //这里注意如果temp为int类型,但是res是double分数,所以temp需为double
    }
printf("1/1+...+1/%d=%.16f",i,result); //题目指明为16位小数,所以直接设置为%.16f
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    int m;
    int i;
    int res = 0;
    printf("Input:");
    scanf("%d", &m);
    // 1.取得小于m的最大n
    for (i = 1; i <= m; i++) {
        res += i;
        if (res > m) {
            break;
        }
    }
    // res=0;
    // for(j=1;j<i-1;j++)res+=j;
    printf("n=%d,sum=%d",i-1,res-i); //得到的是大于m的值,故需要减去当前的n
}



















