Showing posts with label C言語. Show all posts
Showing posts with label C言語. Show all posts

Thursday, October 13, 2016

C (programming language): time (Unix): The Duration of Execution of Printing Out 1 to 120,000,000

Command:

$ cat 120million.c


Result:

#include<stdio.h>

int main()
{
for (long n=1; n<=120000000; n++){
printf("%ld\n", n);
}
}


Command:

$ gcc 120million.c
$ time ./a.out


Result:

1
2
3
...
119999998
119999999
120000000

real 3m10.250s
user 0m40.043s
sys 1m5.333s

C (programming language): Power of Two

Command:

$ cat poweroftwo.c


Result:

#include <stdio.h>
#include <math.h>

int main(){
for (int n=1; n <= 100; n++){
printf("%d:%ld\n", n, (long) pow(2,n));
}
return 0;
}


Command:

$ gcc poweroftwo.c
$ ./a.out


Result:

1:2
2:4
3:8
4:16
5:32
6:64
7:128
8:256
9:512
10:1024
11:2048
12:4096
13:8192
14:16384
15:32768
16:65536
17:131072
18:262144
19:524288
20:1048576
21:2097152
22:4194304
23:8388608
24:16777216
25:33554432
26:67108864
27:134217728
28:268435456
29:536870912
30:1073741824
31:2147483648
32:4294967296
33:8589934592
34:17179869184
35:34359738368
36:68719476736
37:137438953472
38:274877906944
39:549755813888
40:1099511627776
41:2199023255552
42:4398046511104
43:8796093022208
44:17592186044416
45:35184372088832
46:70368744177664
47:140737488355328
48:281474976710656
49:562949953421312
50:1125899906842624
51:2251799813685248
52:4503599627370496
53:9007199254740992
54:18014398509481984
55:36028797018963968
56:72057594037927936
57:144115188075855872
58:288230376151711744
59:576460752303423488
60:1152921504606846976
61:2305843009213693952
62:4611686018427387904
63:-9223372036854775808
64:-9223372036854775808
65:-9223372036854775808
66:-9223372036854775808
67:-9223372036854775808
68:-9223372036854775808
69:-9223372036854775808
70:-9223372036854775808
71:-9223372036854775808
72:-9223372036854775808
73:-9223372036854775808
74:-9223372036854775808
75:-9223372036854775808
76:-9223372036854775808
77:-9223372036854775808
78:-9223372036854775808
79:-9223372036854775808
80:-9223372036854775808
81:-9223372036854775808
82:-9223372036854775808
83:-9223372036854775808
84:-9223372036854775808
85:-9223372036854775808
86:-9223372036854775808
87:-9223372036854775808
88:-9223372036854775808
89:-9223372036854775808
90:-9223372036854775808
91:-9223372036854775808
92:-9223372036854775808
93:-9223372036854775808
94:-9223372036854775808
95:-9223372036854775808
96:-9223372036854775808
97:-9223372036854775808
98:-9223372036854775808
99:-9223372036854775808
100:-9223372036854775808

C (programming language): 1 / 2^n

Command:

$ cat testmath.c


Result:

#include <stdio.h>
#include <math.h>
#include <float.h>

int main(){

int i = 1;

for (int i = 1; i <= 84; i++)
{
printf("%d:%.84f\n", i, 1.0/pow(2,i));
}
}


Command:

$ gcc testmath.c
$ ./a.out


Result:

1:0.500000000000000000000000000000000000000000000000000000000000000000000000000000000000
2:0.250000000000000000000000000000000000000000000000000000000000000000000000000000000000
3:0.125000000000000000000000000000000000000000000000000000000000000000000000000000000000
4:0.062500000000000000000000000000000000000000000000000000000000000000000000000000000000
5:0.031250000000000000000000000000000000000000000000000000000000000000000000000000000000
6:0.015625000000000000000000000000000000000000000000000000000000000000000000000000000000
7:0.007812500000000000000000000000000000000000000000000000000000000000000000000000000000
8:0.003906250000000000000000000000000000000000000000000000000000000000000000000000000000
9:0.001953125000000000000000000000000000000000000000000000000000000000000000000000000000
10:0.000976562500000000000000000000000000000000000000000000000000000000000000000000000000
11:0.000488281250000000000000000000000000000000000000000000000000000000000000000000000000
12:0.000244140625000000000000000000000000000000000000000000000000000000000000000000000000
13:0.000122070312500000000000000000000000000000000000000000000000000000000000000000000000
14:0.000061035156250000000000000000000000000000000000000000000000000000000000000000000000
15:0.000030517578125000000000000000000000000000000000000000000000000000000000000000000000
16:0.000015258789062500000000000000000000000000000000000000000000000000000000000000000000
17:0.000007629394531250000000000000000000000000000000000000000000000000000000000000000000
18:0.000003814697265625000000000000000000000000000000000000000000000000000000000000000000
19:0.000001907348632812500000000000000000000000000000000000000000000000000000000000000000
20:0.000000953674316406250000000000000000000000000000000000000000000000000000000000000000
21:0.000000476837158203125000000000000000000000000000000000000000000000000000000000000000
22:0.000000238418579101562500000000000000000000000000000000000000000000000000000000000000
23:0.000000119209289550781250000000000000000000000000000000000000000000000000000000000000
24:0.000000059604644775390625000000000000000000000000000000000000000000000000000000000000
25:0.000000029802322387695312500000000000000000000000000000000000000000000000000000000000
26:0.000000014901161193847656250000000000000000000000000000000000000000000000000000000000
27:0.000000007450580596923828125000000000000000000000000000000000000000000000000000000000
28:0.000000003725290298461914062500000000000000000000000000000000000000000000000000000000
29:0.000000001862645149230957031250000000000000000000000000000000000000000000000000000000
30:0.000000000931322574615478515625000000000000000000000000000000000000000000000000000000
31:0.000000000465661287307739257812500000000000000000000000000000000000000000000000000000
32:0.000000000232830643653869628906250000000000000000000000000000000000000000000000000000
33:0.000000000116415321826934814453125000000000000000000000000000000000000000000000000000
34:0.000000000058207660913467407226562500000000000000000000000000000000000000000000000000
35:0.000000000029103830456733703613281250000000000000000000000000000000000000000000000000
36:0.000000000014551915228366851806640625000000000000000000000000000000000000000000000000
37:0.000000000007275957614183425903320312500000000000000000000000000000000000000000000000
38:0.000000000003637978807091712951660156250000000000000000000000000000000000000000000000
39:0.000000000001818989403545856475830078125000000000000000000000000000000000000000000000
40:0.000000000000909494701772928237915039062500000000000000000000000000000000000000000000
41:0.000000000000454747350886464118957519531250000000000000000000000000000000000000000000
42:0.000000000000227373675443232059478759765625000000000000000000000000000000000000000000
43:0.000000000000113686837721616029739379882812500000000000000000000000000000000000000000
44:0.000000000000056843418860808014869689941406250000000000000000000000000000000000000000
45:0.000000000000028421709430404007434844970703125000000000000000000000000000000000000000
46:0.000000000000014210854715202003717422485351562500000000000000000000000000000000000000
47:0.000000000000007105427357601001858711242675781250000000000000000000000000000000000000
48:0.000000000000003552713678800500929355621337890625000000000000000000000000000000000000
49:0.000000000000001776356839400250464677810668945312500000000000000000000000000000000000
50:0.000000000000000888178419700125232338905334472656250000000000000000000000000000000000
51:0.000000000000000444089209850062616169452667236328125000000000000000000000000000000000
52:0.000000000000000222044604925031308084726333618164062500000000000000000000000000000000
53:0.000000000000000111022302462515654042363166809082031250000000000000000000000000000000
54:0.000000000000000055511151231257827021181583404541015625000000000000000000000000000000
55:0.000000000000000027755575615628913510590791702270507812500000000000000000000000000000
56:0.000000000000000013877787807814456755295395851135253906250000000000000000000000000000
57:0.000000000000000006938893903907228377647697925567626953125000000000000000000000000000
58:0.000000000000000003469446951953614188823848962783813476562500000000000000000000000000
59:0.000000000000000001734723475976807094411924481391906738281250000000000000000000000000
60:0.000000000000000000867361737988403547205962240695953369140625000000000000000000000000
61:0.000000000000000000433680868994201773602981120347976684570312500000000000000000000000
62:0.000000000000000000216840434497100886801490560173988342285156250000000000000000000000
63:0.000000000000000000108420217248550443400745280086994171142578125000000000000000000000
64:0.000000000000000000054210108624275221700372640043497085571289062500000000000000000000
65:0.000000000000000000027105054312137610850186320021748542785644531250000000000000000000
66:0.000000000000000000013552527156068805425093160010874271392822265625000000000000000000
67:0.000000000000000000006776263578034402712546580005437135696411132812500000000000000000
68:0.000000000000000000003388131789017201356273290002718567848205566406250000000000000000
69:0.000000000000000000001694065894508600678136645001359283924102783203125000000000000000
70:0.000000000000000000000847032947254300339068322500679641962051391601562500000000000000
71:0.000000000000000000000423516473627150169534161250339820981025695800781250000000000000
72:0.000000000000000000000211758236813575084767080625169910490512847900390625000000000000
73:0.000000000000000000000105879118406787542383540312584955245256423950195312500000000000
74:0.000000000000000000000052939559203393771191770156292477622628211975097656250000000000
75:0.000000000000000000000026469779601696885595885078146238811314105987548828125000000000
76:0.000000000000000000000013234889800848442797942539073119405657052993774414062500000000
77:0.000000000000000000000006617444900424221398971269536559702828526496887207031250000000
78:0.000000000000000000000003308722450212110699485634768279851414263248443603515625000000
79:0.000000000000000000000001654361225106055349742817384139925707131624221801757812500000
80:0.000000000000000000000000827180612553027674871408692069962853565812110900878906250000
81:0.000000000000000000000000413590306276513837435704346034981426782906055450439453125000
82:0.000000000000000000000000206795153138256918717852173017490713391453027725219726562500
83:0.000000000000000000000000103397576569128459358926086508745356695726513862609863281250
84:0.000000000000000000000000051698788284564229679463043254372678347863256931304931640625