a) 运行结果:
a) C语言代码:
/* c how to program 习题3.45 */
#include <stdio.h>
// function main begins program execution
int main( void )
{
//分别定义变量
int number = -1, temp = 1, count = 1;
//获取number的值
while(number < 0){
printf("请输入n的值(非负整数):");
scanf("%d", &number);
//如果number小于0,提示错误并要求重新输入
if(number < 0)
printf("你的输入有误,请重新输入!\n");
}
//使用循环计算阶乖
while( ++temp <= number ){
count *= temp;
}
//输出阶乖的结果
printf("%d的阶乖是:%d\n", number, count);
}
b) 运行结果:
b) C语言代码:
/* c how to program 习题3.45 */
#include <stdio.h>
// function main begins program execution
int main( void )
{
//分别定义变量
int number = -1, loop = 1;
double e = 1.0, jcCount = 1.0;
//获取number的值
while(number < 0){
printf("请输入n的值(非负整数):");
scanf("%d", &number);
//如果number小于0,提示错误并要求重新输入
if(number < 0)
printf("你的输入有误,请重新输入!\n");
}
//计算e的值
while(loop <= number){ //当loopTemp小于number执行循环,累加阶乖的倒数
//计算阶乖
jcCount *= loop;
//计算e的值
e += 1.0 / jcCount;
loop++;
}
//输出e的结果
printf("e = %f\n", e);
}
C) 运行结果:
C) C语言代码:
/* c how to program 习题3.45 */
#include <stdio.h>
// function main begins program execution
int main( void )
{
//分别定义变量
int number = -1, loop = 1, x = 3;
double e = 1.0, jcCount = 1.0, xCount = 1.0;
//获取number的值
while(number < 0){
printf("请输入n的值(非负整数):");
scanf("%d", &number);
//如果number小于0,提示错误并要求重新输入
if(number < 0)
printf("你的输入有误,请重新输入!\n");
}
//计算e的值
while(loop <= number){ //当loopTemp小于number执行循环,累加阶乖的倒数
//计算阶乖
jcCount *= loop;
xCount *= x;
//计算e的值
e += xCount / jcCount;
loop++;
}
//输出e的结果
printf("e = %f\n", e);
}