ScrapExplorer - main.c

Home / lab / c / factorial Lines: 5 | Size: 1176 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* SPDX-License-Identifier: GPL-3.0 2 * factorial 3 * 4 * main.c 5 * 6 * COPYRIGHT NOTICE 7 * Copyright (C) 2024-2025 0x4248 and contributors 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the license is not changed. 10 * 11 * This software is free and open source. Licensed under the GNU general 12 * public license version 3.0 as published by the Free Software Foundation. 13 */ 14 15#include <stdio.h> 16 17__uint128_t factorial(int n) 18{ 19 if (n == 0) 20 { 21 return 0; 22 } 23 else if (n == 1) 24 { 25 return 1; 26 } 27 else 28 { 29 return n * factorial(n - 1); 30 } 31} 32 33void print_uint128_decimal(__uint128_t value) 34{ 35 if (value == 0) 36 { 37 printf("0"); 38 return; 39 } 40 41 char buffer[40]; 42 int pos = sizeof(buffer) - 1; 43 44 buffer[pos] = '\0'; 45 while (value > 0) 46 { 47 buffer[--pos] = '0' + (value % 10); 48 value /= 10; 49 } 50 printf("%s", &buffer[pos]); 51} 52 53int main() 54{ 55 printf("128-bit factorial\n"); 56 printf("Copyright (C) 2025 0x4248\n"); 57 printf("GNU General Public License v3.0\n"); 58 59 __uint128_t result; 60 for (int i = 0; i < 130; i++) 61 { 62 result = factorial(i); 63 printf("%d = ", i); 64 print_uint128_decimal(result); 65 printf("\n"); 66 } 67 return 0; 68}
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.