Compiler/Sample programs: Difference between revisions
Content added Content deleted
m (→{{header|Fibonacci sequence}}: last line number was off by one) |
No edit summary |
||
Line 20: | Line 20: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* |
/* |
||
Hello world |
Hello world |
||
*/ |
*/ |
||
print("Hello, World!\n"); |
print("Hello, World!\n"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 77: | Line 77: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* |
/* |
||
Show Ident and Integers |
Show Ident and Integers |
||
Line 83: | Line 83: | ||
phoenix_number = 142857; |
phoenix_number = 142857; |
||
print(phoenix_number, "\n"); |
print(phoenix_number, "\n"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 154: | Line 154: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* |
/* |
||
All lexical tokens - not syntactically correct, but that will |
All lexical tokens - not syntactically correct, but that will |
||
Line 177: | Line 177: | ||
/* character literal */ '\\' |
/* character literal */ '\\' |
||
/* character literal */ ' ' |
/* character literal */ ' ' |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 240: | Line 240: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/*** test printing, embedded \n and comments with lots of '*' ***/ |
/*** test printing, embedded \n and comments with lots of '*' ***/ |
||
print(42); |
print(42); |
||
print("\nHello World\nGood Bye\nok\n"); |
print("\nHello World\nGood Bye\nok\n"); |
||
print("Print a slash n - \\n.\n"); |
print("Print a slash n - \\n.\n"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 328: | Line 328: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
count = 1; |
count = 1; |
||
while (count < 10) { |
while (count < 10) { |
||
Line 334: | Line 334: | ||
count = count + 1; |
count = count + 1; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 456: | Line 456: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* 100 Doors */ |
/* 100 Doors */ |
||
i = 1; |
i = 1; |
||
Line 463: | Line 463: | ||
i = i + 1; |
i = i + 1; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 601: | Line 601: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
a = (-1 * ((-1 * (5 * 15)) / 10)); |
a = (-1 * ((-1 * (5 * 15)) / 10)); |
||
print(a, "\n"); |
print(a, "\n"); |
||
Line 608: | Line 608: | ||
print(-b, "\n"); |
print(-b, "\n"); |
||
print(-(1), "\n"); |
print(-(1), "\n"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 808: | Line 808: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
print(---------------------------------+++5, "\n"); |
print(---------------------------------+++5, "\n"); |
||
print(((((((((3 + 2) * ((((((2))))))))))))), "\n"); |
print(((((((((3 + 2) * ((((((2))))))))))))), "\n"); |
||
if (1) { if (1) { if (1) { if (1) { if (1) { print(15, "\n"); } } } } } |
if (1) { if (1) { if (1) { if (1) { if (1) { print(15, "\n"); } } } } } |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 1,162: | Line 1,162: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* Compute the gcd of 1071, 1029: 21 */ |
/* Compute the gcd of 1071, 1029: 21 */ |
||
Line 1,174: | Line 1,174: | ||
} |
} |
||
print(a); |
print(a); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 1,295: | Line 1,295: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* 12 factorial is 479001600 */ |
/* 12 factorial is 479001600 */ |
||
Line 1,306: | Line 1,306: | ||
} |
} |
||
print(result); |
print(result); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 1,432: | Line 1,432: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* fibonacci of 44 is 701408733 */ |
/* fibonacci of 44 is 701408733 */ |
||
Line 1,446: | Line 1,446: | ||
} |
} |
||
print(w, "\n"); |
print(w, "\n"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 1,610: | Line 1,610: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* FizzBuzz */ |
/* FizzBuzz */ |
||
i = 1; |
i = 1; |
||
Line 1,626: | Line 1,626: | ||
i = i + 1; |
i = i + 1; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 1,838: | Line 1,838: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* 99 bottles */ |
/* 99 bottles */ |
||
bottles = 99; |
bottles = 99; |
||
Line 1,848: | Line 1,848: | ||
print(bottles, " bottles of beer on the wall\n\n"); |
print(bottles, " bottles of beer on the wall\n\n"); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 2,033: | Line 2,033: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
/* |
/* |
||
Simple prime number generator |
Simple prime number generator |
||
Line 2,054: | Line 2,054: | ||
} |
} |
||
print("Total primes found: ", count, "\n"); |
print("Total primes found: ", count, "\n"); |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 2,368: | Line 2,368: | ||
|- |
|- |
||
| style="vertical-align:top" | |
| style="vertical-align:top" | |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
{ |
{ |
||
/* |
/* |
||
Line 2,411: | Line 2,411: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||