[ create a new paste ] login | about

Link: http://codepad.org/UXSIJM1T    [ raw code | output | fork ]

C, pasted on Jun 15:
#include <stdio.h>
#define N 4

void g(int n, int k, int c)
{
	if (n < c)
	{
		printf("%d", n);
	}
	else
	{
		g(n / c, k, c);
		printf("'%0*d", k, n % c);
	}
}

void f(int n)
{
	int c = 1;
	
	for (int i = 0; i < N; i++)
	{
		c = c * 10;
	}

	int m = n;
	
	if (m < 0)
	{
		printf("-");
		m = m * -1;
	}
	
	g(m, N, c);
	printf("\n");
}

int main()
{
	f(0);
	f(1);
	f(12);
	f(123);
	f(1234);
	f(12345);
	f(101);
	f(1001);
	f(10001);
	f(100001);
	f(1000001);
	f(10000001);
	f(100000001);
	f(1000000001);
	f(-0);
	f(-1);
	f(-12);
	f(-123);
	f(-1234);
	f(-12345);
	f(1000);
	return 0;
}
/* end */


Output:
1
2
In function 'f':
Line 21: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: