mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Fixed bug that would intermittently arise from multiple contexts having the same pointer (should preferably be fixed in a different way later). Free all the arenas before codegen. Change "next" to "nextcase". Allow missing function parameters. Add "inline" structs.
This commit is contained in:
36
resources/rosettacode/antiprime.c3
Normal file
36
resources/rosettacode/antiprime.c3
Normal file
@@ -0,0 +1,36 @@
|
||||
module antiprime;
|
||||
import std::io;
|
||||
|
||||
extern func int printf(char* message, ...);
|
||||
|
||||
func int countDivisors(int n)
|
||||
{
|
||||
if (n < 2) return 1;
|
||||
int count = 2;
|
||||
for (int i = 2; i <= n / 2; i++)
|
||||
{
|
||||
if (n % i == 0) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
func int main()
|
||||
{
|
||||
int maxDiv;
|
||||
int count;
|
||||
io::println("The first 20 anti-primes are:");
|
||||
int n = 1;
|
||||
while (count < 20)
|
||||
{
|
||||
int d = countDivisors(n);
|
||||
if (d > maxDiv)
|
||||
{
|
||||
printf("%d ", n);
|
||||
maxDiv = d;
|
||||
count++;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
io::println("");
|
||||
return 0;
|
||||
}
|
||||
7
resources/rosettacode/helloworld.c3
Normal file
7
resources/rosettacode/helloworld.c3
Normal file
@@ -0,0 +1,7 @@
|
||||
import std::io;
|
||||
|
||||
func int main()
|
||||
{
|
||||
io::println("Hello world");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user