c how to program 习题4.14

发布于2020-06-16 945 热度

运行结果:

C语言代码:

/* c how to program 习题4.14
** 计算1-5的阶乖 */
#include <stdio.h>
#include <math.h>
// function main begins program execution
int main( void )
{
    //定义变量x为整数,n为阶乘
    int x, n = 1;
    //使用循环计算阶乖
    printf("计算x的阶乖(x!):\nx\tx!\n");
    for(x = 1; x <= 5; x++){
            n *= x;
            //打印结果
            printf("%d\t%d\n", x, n);
    }
}

记录工作,记录学习,分享知识,分享经验……