Exemple #1
0
char *mult(char *a, char *b)
{
	char *pp;
	int lena, lenb, n;
	char *tmp;

	lena = strlen(a);
	lenb = strlen(b);
	n = max_n(lena, lenb);

	reverse(a);
	reverse(b);

	if(n == lenb) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* 1 extra for null char */
	pp = malloc(n*2 + 1);
	pp[n*2] = 0;
	for(int i = 0; i < n*2; i++)
		pp[i] = '0';

	mult1(a, b, pp, n, 0);

	reverse(pp);
	reverse(a);
	reverse(b);
	return pp;
}
Exemple #2
0
unsigned char mcuGetBattery(BOOL bUsbCache, BOOL *pbOnCharge)
{
	BOOL s_bOnCharge;
	static unsigned char s_aucBattery[5] = { 0 };
	unsigned char ucBattery;
	unsigned char ucStatus;
/*
	//command for get battery level
	char acMCU_Cmd[] = 
	{
		0x55, 0x11, 0x4D, 0x4D, 0x00, 0x01, 0x00, 0x53, 0x48, 0x52, 0x54, 
		0x00, 0x01, 0x00, 0x01, 0x0D, 0x00, 0x00, 0x00, 0xFC, 0x01, 0xAA
	};
	char acResponse[3];
 */
	
	if (bUsbCache)
	{
		unsigned char ucRet = max_n(s_aucBattery, sizeof(s_aucBattery) / sizeof(s_aucBattery[0]));
		
		if (pbOnCharge != NULL)
			*pbOnCharge = s_bOnCharge;

		if (ucRet != 0)
			return ucRet;
	}

	if (mcuGetReport(FALSE, &ucBattery, &ucStatus))
	{
		int i;
		for (i = sizeof(s_aucBattery) / sizeof(s_aucBattery[0]) - 1; i != 0; --i)
			s_aucBattery[i] = s_aucBattery[i - 1];
		s_aucBattery[0] = ucBattery;

		s_bOnCharge = ((ucStatus & 0x50) == 0 && (ucStatus & 0x40) == 0 ? FALSE : TRUE);
		if (pbOnCharge != NULL)
			*pbOnCharge = s_bOnCharge;
			
		return max_n(s_aucBattery, sizeof(s_aucBattery) / sizeof(s_aucBattery[0]));
	}
	else
		return 0;
}
Exemple #3
0
/* berechnet die Breite der Y-Achsen Beschriftung */
static gint get_y_label_width(CoordSystem *coord, PangoLayout *layout)
{
    gint pos, neg, title;

    pos = get_number_size(coord->max_y, coord->fract_y, WIDTH, layout);
    neg = get_number_size(coord->min_y, coord->fract_y, WIDTH, layout);
    title = get_text_size(WIDTH, layout, "%s [%s]",
                          coord->y_title, coord->y_unit);

    return max_n(3, pos, neg, title);
}
Exemple #4
0
/* berechnet die Höhe der X-Achsen Beschriftung */
static gint get_x_label_height(CoordSystem *coord, PangoLayout *layout)
{
    gint pos, neg, title;

    pos = get_number_size(coord->max_x, coord->fract_x, HEIGHT, layout);
    neg = get_number_size(coord->min_x, coord->fract_x, HEIGHT, layout);
    layout_printf(layout, "%s [%s]", coord->x_title, coord->x_unit);
    title = get_text_size(HEIGHT, layout, "%s [%s]",
                          coord->x_title, coord->x_unit);

    return max_n(3, pos, neg, title);
}
Exemple #5
0
int main(int argc, char const *argv[])
{
	// given array, find max (a[j] - a[i]) ; i<j
	srand(time(NULL));
	int n = 10;
	int arr[n];
	int i;
	for ( i = 0; i < n; ++i)
	{
		arr[i] = rand()%100;
		printf("%d ", arr[i]);
	}
	printf("\n");
	//int diff = max_n2(arr,n);
	int diff = max_n(arr,n);
	printf("Maximum gap: %d\n", diff);
	return 0;
}
Exemple #6
0
int main(int argc, char const *argv[])
{
	// given array, find max abs(a[i] - a[j]) ; i!=j
	srand(time(NULL));
	int n = SIZE;
	int arr[n];
	int i;
	for ( i = 0; i < n; ++i)
	{
		arr[i] = rand()%100;
		printf("%d ", arr[i]);
	}
	printf("\n");
	//int diff = max_n2(arr,n);

	//int diff = max_sort(arr,n);

	int diff = max_n(arr,n);

	printf("DIFF : %d\n", diff);
	return 0;
}
Exemple #7
0
int main(void)
{
	max_n(3,1,2,3);
	max_n(5,2,4,6,5,3);
	return 0;
}