这个程序做了什么 [英] what this program do

查看:90
本文介绍了这个程序做了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



C程序计算出来的是什么?

我尽我所能但却无法理解。


#include< stdio.h>

main()

{

long a = 1000,b = 0,c = 2800, d,e = 0,f [2801],g;

for(; bc;)f [b ++] = a / 5;

for(; d = 0 ,g = c * 2; c- = 14,printf(%。4ld,e + d / a),e = d%a)

(b = c; d + = f [b] * a,f [b] = d% - g,d / = g - , - b; d * = b);

}

解决方案

Three Headed Monkey写道:


轰鸣声C程序计算什么?



没什么用。看起来像混淆的C竞赛中的一个条目,

或者是一个滥用语言的过于聪明的程序员的好例子。


I我尽了最大努力但却无法理解。



为什么不运行它,看看它产生了什么?


这就是说,没有意义 - 你会从来没有心甘情愿地写这个代码,比如

这个,如果你在一个程序中找到它你维护你应该

尽快把它撕掉。


Three Headed Monkey写道:


轰鸣声C程序计算什么?

我尽我所能但不能我没弄明白。


#include< stdio.h>

main()

{

长a = 1000,b = 0,c = 2800,d,e = 0,f [2801],g;

for(; bc;)f [b ++] = a / 5;

for(; d = 0,g = c * 2; c- = 14,printf("%。4ld",e + d / a),e = d% a)

for(b = c; d + = f [b] * a,f [b] = d% - g,d / = g - , - b; d * = b);

}



输出是

03140159026503580979032308460264033803270950028804 19071609390937051005820097049404590230078106400628 06200899086208030482053402110 706079802140808065103 2802300664

07090384046009550058022301720535094008120848011107 45002804100270019308520110055509640462029408950493 00380196044208810097056605930344061208470564082303 7806780316

05270120019009140564085606920346003408610045043206 64082103390360072600240914012703720458070006600631 05580817048801520092009602820925040901710536043607 8902590036

00010133005300540882004606520138041406950194015101 60094303050727003605750959019503090218061107380193 02610179031005110854080704460237099602740956073501 8805750272

04890122079308180301019409120983036703360244006506 64030806020139049406390522047307190070021709860094 03700277005309210717062903170675023804670481084607 6609400513


如果我们拿出一些零(它可能有一个bug)我们得到


31415926535897932384626433832795028841971 ...

PI的数字是:


3.141592653589793238462643383279502884197169399375 ...

-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32


jacob navia写道:


输出是

03140159026503580979032308460264033803270950028804 19071609390937051005820097049404590230078106400628 06200899086208030482053402110706079802140808065103 2802300664

07090384046009550058022301720535094008120848011107 45002804100270019308520110055509640462029408950493 00380196044208810097056605930344061208470564082303 7806780316

05270120019009140564085606920346003408610045043206 64082103390360072600240914012703720458070006600631 05580817048801520092009602820925040901710536043607 8902590036

00010133005300540882004606520138041406950194015101 60094303050727003605750959019503090218 061107380193 02610179031005110854080704460237099602740956073501 8805750272

04890122079308180301019409120983036703360244006506 64030806020139049406390522047307190070021709860094 03700277005309210717062903170675023804670481084607 6609400513


。如果我们采取一些零出(它有一个缺陷可能),我们得到


31415926535897932384626433832795028841971 ...

PI编号为:


3.141592653589793238462643383279502884197169399375 ...



啊哈!好抓!


我更改了格式说明符并添加了最终换行符:


#include< stdio.h>

main()

{

long a = 1000,b = 0,c = 2800,d,e = 0,f [2801],g;

for(; bc;)f [b ++] = a / 5;

for(; d = 0,g = c * 2; c- = 14,printf (%ld,e + d / a),e = d%a)

(b = c; d + = f [b] * a,f [b] = d% --g,d / = g - , - b; d * = b);

printf(" \ n");

}


,其打印:


31415926535897932384626433832795028841971693993751 05829749445923078164062862089986280348253421170679 82148086513282306647093844609555822317253594081284 81117452841027019385211055596446229489549338196442 88197566593344612847564823378678316527120190914564 85669234634861454326648213393607262491412737245870 06606315588174881529296282925409171536436789259361 13353548824665213841469519415116094330572736575959 19530921861173819326117931051185480744623799627495 67351885752724891227938183011949129833673362446566 430 86021394946395224737197021798694370277539217176 29317675238467481846766940513

:-)

-

Morris Dovey

DeSoto太阳能

美国爱荷华州德索托
http:// www.iedu.com/DeSoto/



What does bellow C program calculate?
I tried my best but couldn''t figured it out.

#include <stdio.h>
main()
{
long a=1000,b=0,c=2800,d,e=0,f[2801],g;
for(;b-c;) f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4ld",e+d/a),e=d%a)
for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
}

解决方案

Three Headed Monkey wrote:

What does bellow C program calculate?

Nothing useful. Looks like either an entry in the obfuscated C contest,
or a good example of an overly-smart programmer abusing the language.

I tried my best but couldn''t figured it out.

Why not run it and see what it produces?

That said, there''s no point - you will never willingly write code like
this, and if you find it in a programme you''re maintaining you should
rip it out asap.


Three Headed Monkey wrote:

What does bellow C program calculate?
I tried my best but couldn''t figured it out.

#include <stdio.h>
main()
{
long a=1000,b=0,c=2800,d,e=0,f[2801],g;
for(;b-c;) f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4ld",e+d/a),e=d%a)
for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
}

The output of that is
03140159026503580979032308460264033803270950028804 19071609390937051005820097049404590230078106400628 06200899086208030482053402110706079802140808065103 2802300664
07090384046009550058022301720535094008120848011107 45002804100270019308520110055509640462029408950493 00380196044208810097056605930344061208470564082303 7806780316
05270120019009140564085606920346003408610045043206 64082103390360072600240914012703720458070006600631 05580817048801520092009602820925040901710536043607 8902590036
00010133005300540882004606520138041406950194015101 60094303050727003605750959019503090218061107380193 02610179031005110854080704460237099602740956073501 8805750272
04890122079308180301019409120983036703360244006506 64030806020139049406390522047307190070021709860094 03700277005309210717062903170675023804670481084607 6609400513

If we take some zeroes out (it has a bug maybe) we get

31415926535897932384626433832795028841971 ...

The number PI is:

3.141592653589793238462643383279502884197169399375 ...
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32


jacob navia wrote:

The output of that is
03140159026503580979032308460264033803270950028804 19071609390937051005820097049404590230078106400628 06200899086208030482053402110706079802140808065103 2802300664
07090384046009550058022301720535094008120848011107 45002804100270019308520110055509640462029408950493 00380196044208810097056605930344061208470564082303 7806780316
05270120019009140564085606920346003408610045043206 64082103390360072600240914012703720458070006600631 05580817048801520092009602820925040901710536043607 8902590036
00010133005300540882004606520138041406950194015101 60094303050727003605750959019503090218061107380193 02610179031005110854080704460237099602740956073501 8805750272
04890122079308180301019409120983036703360244006506 64030806020139049406390522047307190070021709860094 03700277005309210717062903170675023804670481084607 6609400513

If we take some zeroes out (it has a bug maybe) we get

31415926535897932384626433832795028841971 ...

The number PI is:

3.141592653589793238462643383279502884197169399375 ...

Aha! Good catch!

I changed the format specifier and added a final newline:

#include <stdio.h>
main()
{
long a=1000,b=0,c=2800,d,e=0,f[2801],g;
for(;b-c;) f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%ld",e+d/a),e=d%a)
for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
printf("\n");
}

Which prints:

31415926535897932384626433832795028841971693993751 05829749445923078164062862089986280348253421170679 82148086513282306647093844609555822317253594081284 81117452841027019385211055596446229489549338196442 88197566593344612847564823378678316527120190914564 85669234634861454326648213393607262491412737245870 06606315588174881529296282925409171536436789259361 13353548824665213841469519415116094330572736575959 19530921861173819326117931051185480744623799627495 67351885752724891227938183011949129833673362446566 43086021394946395224737197021798694370277539217176 29317675238467481846766940513

:-)

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/


这篇关于这个程序做了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆