题解 | #阶乘#

阶乘

https://www.nowcoder.com/practice/e58c8a55162d49c48115bdfa5da7da56

#include <stdio.h>
int jiecheng(int t){
    int temp=1;;
    for(int i=1;i<=t;i++){
        temp*=i;
    }
    return temp;
}
int main() {
    int n;int y1=0;int y2=0;
    while (scanf("%d ", &n) != EOF) { 
        if(n%2==1){
            int temp1=0,temp2=0;
            for(int i=n;i>0;i=i-2){
                temp1=jiecheng(i)+temp1;
            }
            y1=temp1;
            for(int i=n-1;i>0;i=i-2){
                temp2+=jiecheng(i);
            }
            y2=temp2;
        }else if(n%2==0){
            int temp1=0,temp2=0;
            for(int i=n-1;i>0;i=i-2){
                temp1=jiecheng(i)+temp1;
            }
            y1=temp1;
            for(int i=n;i>0;i=i-2){
                temp2+=jiecheng(i);
            }
            y2=temp2;
        }
        printf("%d %d",y1,y2);
    }
    return 0;
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务