c++笔试题两道,求解其中一道

1.Implement a functionthat prints the numbers from 1 to 100.But for multiples of three(3) print “Zif”insteadof the number and for the multiples of five(5) print “Nab”. For numbers whichare multiples of both three and five print “ZifNab”.

void printZifNab(int from, int to)
	{
		if (from > to) return;
		for (int i = from; i <= to; i++)
		{
			if ((i % 3 == 0) && (i % 5 == 0))
			{
				printf("ZifNab\n");
			}
			else if ((i % 3 == 0))
			{
				printf("Zif\n");
			}  
			else if ((i % 5 == 0))
			{
				printf("Nab\n");
			}
			else {
				printf("%d\n", i);
			}
		}
	}

2. unsigned short ConvertRGB888toRBG565(unsigned int nSourceColor)

Parameters: nSourceColor – 32 Bits RGB color to convert.

Return: The converted color as a 16 Bits RGB color.

This function converts an RGB 32 bits color format to RGB 16 bits color format. The 32 bits formats contains 8 bits of empty padding.8 bits for RED.8 bits for GREEN and 8 bits for BLUE. In that order. Now you have to down convert this value to 16 bits. By have 5 bits for RED, 6 bits for GREEN and finally 5 bits for the BLUE.

Color Help:

Red = 0x00FF0000

Green = 0x0000FF00;

Blue = 0x000000FF;

White = 0x00FFFFFF;

Black = 0x00000000;

第二题求解。


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值