| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

#include<stdio.h>
int main()
{
double x,y,z,a,b,c;
scanf("%lf",&x);
b = 1;
y = 1;
for(z=1;z<=x;z++){
for(a=1;a<=z;a++){
b = b*a;
}
c = 1/b;
y = y +c;
}
printf("%.8lf\n",y);
return 0;
}

https://www.

//online parser: https://www.bccn.net/run/

```#include <stdio.h>

int main(int argc, char *argv[])
{
double x, y, z, a, b;

for(x= 3, y = 1, z = 1; z <= x; z++) {
b = 1;
for(a = 1; a <= z; a++) b = b * a;
b = 1 / b;
y = y + b;
}
printf("%.8lf\n",y);

return 0;
}```

//online parser: https://www.bccn.net/run/

```#include <stdio.h>
#include <stdlib.h>

//#define SUB1
#ifdef SUB1
int sub1(int argc, char *argv[])
{
double x, y, z, a, b, c;
x = 3.0;
b = 1;
y = 1;
for(z = 1; z <= x; z++) {
for(a = 1; a <= z; a++){
b = b * a;
}
c = 1 / b;
y = y + c;
}
printf("%.8lf\n",y);

return 0;
}
#else
int sub2(int argc, char *argv[])
{
double x, y, z, a, b;

for(x= 3, y = 1, z = 1; z <= x; z++) {
b = 1;
for(a = 1; a <= z; a++) b = b * a;
b = 1 / b;
y = y + b;
}
printf("%.8lf\n",y);

return 0;
}
#endif

int main(int argc, char *argv[])
{
system("ls");
#ifdef SUB1
system("gcc -E *.c -o va.e");
#else
system("gcc -E *.c -o vb.e");
#endif
system("ls");
system("diff va.e vb.e");

return 0;
}```

check different parts, good luck!
linux diff result:
------------------------------------------------
9028259.c
9028259.out
9028259.txt
va.e
vb.e
9028259.c
9028259.out
9028259.txt
va.e
vb.e
1c1
< # 1 "4218938.c"
---
> # 1 "9028259.c"
6c6
< # 1 "4218938.c"
---
> # 1 "9028259.c"
847c847
< # 2 "4218938.c" 2
---
> # 2 "9028259.c" 2
1909c1909,1910
< # 3 "4218938.c" 2
---
> # 3 "9028259.c" 2
> # 24 "9028259.c"
1911,1915c1912,1913
<
<
<
< # 6 "4218938.c"
< int sub1(int argc, char *argv[])
---
> # 24 "9028259.c"
> int sub2(int argc, char *argv[])
1917,1926c1915,1921
<     double x, y, z, a, b, c;
<     x = 3.0;
<     b = 1;
<     y = 1;
<     for(z = 1; z <= x; z++) {
<         for(a = 1; a <= z; a++){
<             b = b * a;
<         }
<         c = 1 / b;
<         y = y + c;
---
>     double x, y, z, a, b;
>
>     for(x= 3, y = 1, z = 1; z <= x; z++) {
>         b = 1;
>         for(a = 1; a <= z; a++) b = b * a;
>         b = 1 / b;
>         y = y + b;
1932c1927,1928
< # 40 "4218938.c"
---
>
>
1937c1933,1935
<     system("gcc -E *.c -o va.e");
---
>
>
>     system("gcc -E *.c -o vb.e");
1939a1938
>     system("diff va.e vb.e");
1940a1940
>     return 0;

```#include <stdio.h>
#include <assert.h>

// 计算 1/0! + 1/1! + 1/2! + 1/3! + ... + 1/n!
int main( void )
{
unsigned n;
if( scanf("%u",&n) != 1 )
return 1; // 输入错误
if( n > 20 )
return 1; // 溢出，因为 21! 需要的位数超过64bits

double e = 1;
unsigned long long factorial = 1;
for( unsigned i=0; i!=n; ++i )
{
factorial *= i+1;
e += 1.0/factorial;
}
printf( "%.8f\n", e );
}```
• 6
• 1/1页
• 1