/
printf(", total).4f\ i <
for (j = i;= n;/
total += temp;= n;
double total = 0.h"
double total = 0:%:%;;= n;嵌套循环, temp = 1.0, total); j >.0; i <.0;
total = total + temp.0; i;;
/%d" j, &n); j--)
temp = temp / i++)
{
temp = temp /
}
return total;
double fact(int n)
{
int i.0;= 1;n"
}
int main(void)
{
int i; i++)
{
temp = 1, temp = 1; i <;
for (i = 1;调用函数
total = 0.4f\.0;嵌套循环
total = 0;
scanf(", fact(n));/
// i, n;调用函数;n".4f\一重循环
for (i = 1:%; i++)
{
temp = temp /一重循环;, j;
total = total + temp;
for (i = 1#include "
}
printf("
}
printf("n"
return 0
/
total);嵌套循环;调用函数; i++)
total += temp /.0;一重循环
&n).4f\= n.4f\ j--)
total = total + temp /
}
int main(void)
{
int i;%d"
/= j;
printf("
return 0
j;= n;n"= 1
n; i++)
{
temp = 1;n" i <.4f\.0; i++)
total = total + temp /
scanf("
for (i = 1;/
for (i = 1;
double total = 0.0;iostream>= i.0;
for (j = i;
temp = 1;
using namespace std;;
fact(n))
total); j >
/
double total = 0; i < i <;
printf("调用函数
total = 0;n":%:%:%;一重循环
for (i = 1;/.0;嵌套循环
total = 0;= n;
return total
#include "stdio.h"
double fact(int n)
{
int i;
double total = 0.0, temp = 1.0;
for (i = 1; i <= n; i++)
{
temp = temp / i;
total = total + temp;
}
return total;
}
int main(void)
{
int i, j, n;
double total = 0.0, temp = 1.0;
scanf("%d", &n);
//一重循环
for (i = 1; i <= n; i++)
{
temp = temp / i;
total += temp;
}
printf("一重循环:%.4f\n", total);
//调用函数
total = 0.0;
printf("调用函数:%.4f\n", fact(n));
//嵌套循环
total = 0.0;
for (i = 1; i <= n; i++)
{
temp = 1.0;
for (j = i; j >= 1; j--)
temp = temp / j;
total = total + temp;
}
printf("嵌套循环:%.4f\n", total);
return 0;
}
这个是第一种:
#include
void main()
{
int i,j=1,N;
printf("请输入N的值:\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
j*=i;
printf("%d的阶乘是:%d\n",N,j);
}
这个是第二种:
#include
int fact(int n)
{
int ji=1,i;
for(i=1;i<=n;i++)
ji*=i;
return ji;
}
void main()
{ int N,ji;
printf("请输入N的值:\n");
scanf("%d",&N);
ji=fact(N);
printf("%d的阶乘是:%d\n",N,ji);
}
第三种不太理解。。。不好意思。
#include
using namespace std;
double fact(int n)
{
int i;
double total = 0.0, temp = 1.0;
for (i = 1; i <= n; i++)
total = total + temp /= i;
return total;
}
int main(void)
{
int i, j, n;
double total = 0.0, temp = 1.0;
scanf("%d", &n);
//一重循环
for (i = 1; i <= n; i++)
total += temp /= i;
printf("一重循环:%.4f\n", total);
//调用函数
total = 0.0;
printf("调用函数:%.4f\n", fact(n));
//嵌套循环
total = 0.0;
for (i = 1; i <= n; i++)
{
temp = 1.0;
for (j = i; j >= 1; j--)
total = total + temp /= j;
printf("嵌套循环:%.4f\n", total);
return 0;
}