gcc 3.4.5
Version of implementation gcc of programming language CVersion of gcc compiler.
Examples:
Factorial - C, Objective-C (67):
This example uses recursive factorial definition. Note that 13! and larger causes an overflow, so the last lines of the output look like this:
13! = 1932053504
14! = 1278945280
15! = 2004310016
16! = 2004189184
#include <stdlib.h> /* needed for EXIT_SUCCESS */
#include <stdio.h>
unsigned long long factorial(unsigned long long n)
{
if (n == 0) {
return 1;
} else {
return n * factorial (n - 1);
}
}
int main(void)
{
int n;
for (n = 0; n <= 16; n++) {
printf("%i! = %lld\n", n, factorial(n));
}
return EXIT_SUCCESS;
}
Hello, World! - C, Objective-C, C++ (68):
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
Fibonacci numbers - C, Objective-C (122):
This example uses recursive definition of Fibonacci numbers. Note the difference from C++ example: loop counter must be declared outside of the loop, and printf is used for output instead of std::out.
#include <stdio.h>
int fibonacci(int n)
{
return ( n<=2 ? 1 : fibonacci(n-1) + fibonacci(n-2) );
}
int main(void)
{
int n;
for (n=1; n<=16; n++)
printf("%d, ", fibonacci(n));
printf("...\n");
return 0;
}
Comments
]]>blog comments powered by Disqus
]]>