More than one way to do it...
Posted Feb 9, 2008 16:56 UTC (Sat) by
im14u2c (subscriber, #5246)
In reply to:
Oh, it's easy by rsidd
Parent article:
Interview: Mark "Markey" Kretschmann (Not the Gentoo Weekly News)
Let's ban C then...
#include <stdio.h>
int times_two_a(int x) { return x * 2; }
int times_two_b(int x) { return x << 1; }
int times_two_c(int x) { return x + x; }
int main(void)
{
int i, j;
char buf[3];
for (i = 0; i < 10; i++)
printf("%d times two is %d\n", i, times_two_a(i));
i = 0;
while (i < 10)
{
j = times_two_b(i);
printf("%d times two is %d\n", i, j);
}
i = 0;
do
{
sprintf(buf, "%d", i);
fputs(buf, stdout);
fputs(" times two is ", stdout);
sprintf(buf, "%d", times_two_c(i));
fputs(buf, stdout);
} while (++i < 10);
return 0;
}
(
Log in to post comments)