Four lines of code to calculate a 800-bit weird Program)

Source: Internet
Author: User
Weird program for exact PI values
Pi1.c (487 bytes)/pi2.c (552 bytes)

The former is called an alien program ..
In the four rows, the PI is calculated to the fourth digit after the decimal point. It is really not written by people.. Q
The latter statement is quite strange ..

---------------------------

/* A year of obfuscated C Contest :*/

Long A = 10000, B, c = 2800, d, e, f [2801], G;
Main () {for (; B-c;) f [B ++] = A/5;
For (; D = 0, G = C * 2; C-= 14, printf ("%. 4D", e + D/A), E = D %)
For (B = C; D + = f [B] * A, F [B] = D % -- g, D/= g --, -- B; D * = B );}

/* (The first line of the original program is int A = 10000, B, c...
The upper int is only 2-byte, So I change it to long so that each platform has
Run)
Run)
(This program can calculate the PI value of the first 800 bits in C)
(This program is recorded in the sci. Math FAQ. The original author is unknown. I guess it's an alien :)*/

Run successfully. The answer is correct.

In Unix:
// Pi. C pi. c
# Include
Int A = 10000, B, c = 2800, d, e, f [2801], G;
Main ()
{
For (; B-c ;)
F [B ++] = A/5;
For (; D = 0, G = C * 2; C-= 14, printf ("%. 4D", e + D/A), E = D %)
For (B = C; D + = f [B] * A, F [B] = D % -- g, D/= g --, -- B; D * = B );
}

Sun # gcc-O pi. c
Sun #./PI
3141592653589793238462643383279502884197169399375105820974944592307816
4062862089
9862803482534211706798214808651328230664709384460955058223172535940812
8481117450
2841027019385211055596446229489549303819644288109756659334461284756482
3378678316
5271201909145648566923460348610454326648213393607260249141273724587006
6063155881
7488152092096282925409171536436789259036001133053054882046652138414695
1941511609
4330572703657595919530921861173819326117931051185480744623799627495673
5188575272
5188575272
4891227938183011949129833673362440656643086021394946395224737190702179
8609437027
7053921717629317675238467481846766940513200056812714526356082778577134
2757789609
1736371787214684409012249534301465495853710507922796892589235420199561
1212902196
0864034418159813629774771309960518707211349999998372978049951059731732
8160963185

Passed under VC!
Program:
# Include
# Include
Int A = 10000, B, c = 2800, d, e, f [2801], G;
Main ()
{
For (; B-c ;)
F [B ++] = A/5;
For (; D = 0, G = C * 2; C-= 14, printf ("%. 4D", e + D/A), E = D %)
For (B = C; D + = f [B] * A, F [B] = D % -- g, D/= g --, -- B; D * = B );
Return 0;
}
Result:
3141592653589793238462643383279502884197169399375105820974944592307816
4062862089
9862803482534211706798214808651328230664709384460955058223172535940812
8481117450
2841027019385211055596446229489549303819644288109756659334461284756482
3378678316
5271201909145648566923460348610454326648213393607260249141273724587006
6063155881
7488152092096282925409171536436789259036001133053054882046652138414695
1941511609
4330572703657595919530921861173819326117931051185480744623799627495673
5188575272
4891227938183011949129833673362440656643086021394946395224737190702179
8609437027
7053921717629317675238467481846766940513200056812714526356082778577134
2757789609
1736371787214684409012249534301465495853710507922796892589235420199561
1212902196
0864034418159813629774771309960518707211349999998372978049951059731732
8160963185

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.