fork download
  1. #include <stdio.h>
  2.  
  3. // ① 3の累乗を計算してresult配列に格納する関数
  4. void power3(unsigned long result[]) {
  5. result[0] = 1; // 3の0乗は1
  6. for (int i = 1; i < 100; i++) {
  7. result[i] = result[i-1] * 3; // 前の結果に3を掛けて次の値を計算
  8. }
  9. }
  10.  
  11. // ② result配列の内容を表示する関数
  12. void print_result(unsigned long result[]) {
  13. for (int i = 1; i < 100; i++) { // 1乗から99乗まで表示
  14. printf("3^%d = %lu\n", i, result[i]);
  15. }
  16. }
  17.  
  18. int main() {
  19. unsigned long result[100] = {0}; // 結果を格納する配列
  20.  
  21. // 3の累乗を計算して配列に格納
  22. power3(result);
  23.  
  24. // 結果を表示
  25. print_result(result);
  26.  
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
3^1 = 3
3^2 = 9
3^3 = 27
3^4 = 81
3^5 = 243
3^6 = 729
3^7 = 2187
3^8 = 6561
3^9 = 19683
3^10 = 59049
3^11 = 177147
3^12 = 531441
3^13 = 1594323
3^14 = 4782969
3^15 = 14348907
3^16 = 43046721
3^17 = 129140163
3^18 = 387420489
3^19 = 1162261467
3^20 = 3486784401
3^21 = 10460353203
3^22 = 31381059609
3^23 = 94143178827
3^24 = 282429536481
3^25 = 847288609443
3^26 = 2541865828329
3^27 = 7625597484987
3^28 = 22876792454961
3^29 = 68630377364883
3^30 = 205891132094649
3^31 = 617673396283947
3^32 = 1853020188851841
3^33 = 5559060566555523
3^34 = 16677181699666569
3^35 = 50031545098999707
3^36 = 150094635296999121
3^37 = 450283905890997363
3^38 = 1350851717672992089
3^39 = 4052555153018976267
3^40 = 12157665459056928801
3^41 = 18026252303461234787
3^42 = 17185268762964601129
3^43 = 14662318141474700155
3^44 = 7093466277004997233
3^45 = 2833654757305440083
3^46 = 8500964271916320249
3^47 = 7056148742039409131
3^48 = 2721702152408675777
3^49 = 8165106457226027331
3^50 = 6048575297968530377
3^51 = 18145725893905591131
3^52 = 17543689534297670161
3^53 = 15737580455473907251
3^54 = 10319253219002618521
3^55 = 12511015583298303947
3^56 = 639558602475808609
3^57 = 1918675807427425827
3^58 = 5756027422282277481
3^59 = 17268082266846832443
3^60 = 14910758653121394097
3^61 = 7838787811945079059
3^62 = 5069619362125685561
3^63 = 15208858086377056683
3^64 = 8733086111712066817
3^65 = 7752514261426648835
3^66 = 4810798710570394889
3^67 = 14432396131711184667
3^68 = 6403700247714450769
3^69 = 764356669433800691
3^70 = 2293070008301402073
3^71 = 6879210024904206219
3^72 = 2190886001003067041
3^73 = 6572658003009201123
3^74 = 1271229935318051753
3^75 = 3813689805954155259
3^76 = 11441069417862465777
3^77 = 15876464179877845715
3^78 = 10735904392214433913
3^79 = 13760969102933750123
3^80 = 4389419161382147137
3^81 = 13168257484146441411
3^82 = 2611284305020221001
3^83 = 7833852915060663003
3^84 = 5054814671472437393
3^85 = 15164444014417312179
3^86 = 8599843895832833305
3^87 = 7352787613788948299
3^88 = 3611618767657293281
3^89 = 10834856302971879843
3^90 = 14057824835206087913
3^91 = 5279986358199160507
3^92 = 15839959074597481521
3^93 = 10626389076373341331
3^94 = 13432423155410472377
3^95 = 3403781318812313899
3^96 = 10211343956436941697
3^97 = 12187287795601273475
3^98 = 18115119313094268809
3^99 = 17451869791863703195