Programming in C of FC tutorial

###Programming In C GCC’s funcitionality:
gcc command calls a compiler(which transforms a higher level language into assembler), an assembler translates assembler into object files(machine instructions), and a linker, which combines several object files into an executable.

launchpad.net is a unique collaboration and hosting platform for free software. http://www.launchpad.net.

###Programming In C II Example code:

#include <stdio.h>
#define VERSION "1.0"

/* 
 * Runs a prime check on a given integer, return
 * 1 when the integer is a prime number, 0 otherwise
 */
int isPrime(int prime)
{
	int count = 2;

	// Catch two special cases 
	if(prime == 1)
	{
		return 0;
	}
	else if(prime == 2)
	{
		return 1;
	}
	else
	{
		while(prime % count != 0 && count*count<=prime)
		{
			count++;
		}
		return (prime%count==0)?0:1;
	}
}
/*
 * Print version information
 */
void printVersion()
{
	printf("Primality checker version %s\n", VERSION);
	printf("Compiled on %s %s\n", __DATE__, __TIME__);
}

int main()
{
	int i = 1;
	const int max_prime = 2500;

	printVersion();

	for (i = 1; i<max_prime; i++)
	{
		if(isPrime(i))
		{
			printf("%d is prime\n", i);
		}
		else
		{
			printf("%d is not prime\n", i);
		}
	}
	return 0;
}

####Execise 1 Rewrite the for loop in the main() function so it becomes a while loop.

	//for (i = 1; i<max_prime; i++)
	while(i<max_prime)
	{
		if(isPrime(i))
		{
			printf("%d is prime\n", i);
		}
		else
		{
			printf("%d is not prime\n", i);
		}
		i++;
	}

####Execise 2 Rewrite the if…else if…else structure in the isPrime() function to a switch…case structure.

	int count = 2;
	int returnvalue = 0;

	// Catch two special cases 
	switch(prime)
	{
		case 1:
			returnvalue = 0;
			break;
		case 2:
			returnvalue = 1;
			break;
		default:
			while(prime % count != 0 && count*count <= prime)
			{
				count++;
			}
			returnvalue =  (prime % count == 0)?0:1;

	}
	return returnvalue;

####Execise 3 Rewrite the ternary(condition)?value1:value2 to an if..else structure

//return (prime%count==0)?0:1;
if(prime%count == 0)
{
	return 0;
}
else
{
	return 1;
}

####Execise 4 Rewrite the if…else in the main() funciton to make sure the ternary operator

/*
if(isPrime(i))
{
	printf("%d is prime\n", i);
}
else
{
	printf("%d is not prime\n", i);
}
*/
printf("%d %s prime\n", i, isPrime(i)?"is":"is not");

####Execise 5 Replace the isPrime() function by an isOdd() function which return 1 when a given integer is odd.

int isOdd(int odd)
{
	if(odd == 1)
	{
		return 1;
	}
	else
	{
		if(odd%2 == 0)
		{
			return 0;
		}
		else
		{
			return 1;
		}
	}
}

/* Called via */
if(isOdd(i))
{
	printf("%d is Odd\n", i);
}
else
{
	printf("%d is not Odd\n", i);
}

####Execise 6 Design and write a small application which print out the n Fibonacci sequence, where n should be easily modifiable.

#include <stdio.h>

/* The formula is like
 * a(n+2) = a(n)+a(n+1)
 * while when a1 = 1, a2 =1
 */

int Fib(int fib)
{
	if(fib == 1)
	{
		return 1;
	}
	else if(fib == 2)
	{
		return 1;
	}
	else
	{
		return (Fib(fib-1) + Fib(fib-2));
	}
}

int main(int argc, char **argv)
{
	int i;
	int j = 1;

	printf("Please input an integer number\n");
	scanf("%d", &i);

	printf("The Fibonacci sequence is: \n");
	for( j = 1; j <= i; j++)
	{
		printf("a[%d] is %d.\n", j, Fib(j));
	}

	return 0;
}

Because we use recursion here, when the n is too big, the calculation maybe very slow.

Reading Digest of FC3

###Full Circle 3

  1. Page 6 of cn version: DSL(Damn Small Linux), http://www.damnsmalllinux.org, which could be run on 16MB memory’s 486 computer, try it.
  2. Page

FC3 New Words

###Full Circle 3 stunning: 令人惊奇的事物
reveal: 揭露
footrest: 搁脚物
fusion: 融化
compiz+beryl = Compiz Fusion
trawl: 用拖网捕鱼

Reading Digest of FC2

###Full Circle 2 Things to be done:

  1. Page 3, Visit linuxgeekery?
  2. Page 4, OpenMOKO, its recent status. Try to visit www.linuxinsider.com
  3. Page 5, UbuntuHomeServer? www.ubuntuhomeserver.org
  4. Page 16, try VPN, use VPN to reach back home.
  5. Page 25, What is GEDCOM?
  6. Page 27, What is LDS church?
  7. Page 28, Still , try Gramps.
  8. Page 29, ipod support on Ubuntu, libgpod. amaroK
  9. Page 31, try flock, democracy player, songbird, inkscape
  10. Page 34, try game tremulous.
  11. Page 36, try ubuntustudio theme.
  12. Page 37, try to install these applets and integrate them with awesome.

FC2 New Words

###Full Circle 2 affiliate: 归纳,使附属
endorse: 签署,赞同,认可
mean-machine: 概念机
editorial: 编辑的,社论的
dose: 剂量
sarcasm: 嘲讽,挖苦
slip: 滑动,slipped,被忽略
niggle: 拘泥小节
darter: 飞奔者,投掷者
infringement: 侵犯,违反
speculation: 投机,推荐,思索,投机买卖
litigation: 诉讼,起诉
barrier: 障碍物
sentiment: 观点,情绪
interoperability: 互用性,互操作性
imminent: 即将到来的,迫近的
Venezuelan: 委内瑞拉
Bolivarian: 玻利瓦尔
KDE: K Desktop Environment
GNOME: GNU Object Model Environment
chunk: 块
prerequisite: 先决条件
wobbling: 颤抖的
eyecandy: 视觉糖果
tray: 任务栏
purge: 移除
decorator: 装饰,装修
nerds: 书呆子
pinkie: 小手指
imprint: 加痕迹的,刻上记号的
tattoo: 纹身,刻花样的
dip: 舀取, 把…浸入
toe: 脚趾,足尖
toy: 玩弄,调戏
evolve: 发展,进化
podcast: 播客
zealot: 狂热者,犹太教狂热信徒
pingu: 企鹅家族(动画片名)
pimping: 拉皮条,很小的,小气的
nail salon: 美甲沙龙
pingu-pimping: 为企鹅家族拉皮条
Dirty Harry: 《警探哈里》,美国70年代“新警察电影”的代表作,塑造一个典型的硬派新警察形象
spam: 罐头猪肉,垃圾邮件
savvy: 悟性,理解能力,懂行的人
wizz: 奇才,专家
alley: 小径
freak: 怪人,怪事,畸形人
fiancee: 未婚妻
is right up the alley: 正符合我的要求
swipe: 猛击,偷窃,夺得
tetris: 俄罗斯方块
worn: 疲倦的,用旧的
worn-down:
cyber-granny: 电脑奶奶, cyber做前缀代表科技的,电脑的,之类
pasture: 草地,牧场,牧草,放牧
defective: 不完美的,有缺陷的
bode: 停留,继续,遭到,预示, bide的过去式
cheque: 支票
mallware: 广告
user-boo-boo: 用户的反感
dispose: 处理,处置,安排
clog: 阻塞
toaster: 烤面包机,烤面包的人
easy as firing up a toaster: 像用烤面包机加热面包一样简单?
bongos: 邦高鼓
rumble: 隆隆作响
uncover: 发现,揭开,揭露
goodies: 好吃的东西,老妇人,伪君子
pentagon: 五角星
memo: 备忘录
trill: 用颤声唱,用颤声说
trilled: 激动
frank: 坦白,直白
grin: 咧着嘴笑
utter: 发出,表达
wayward: 任性的,不规则的
VPN; Virtual Private Networking
presario: 自由人
dart: 镖,飞镖
stylish: 时髦的
pamphlet: 小册子
power cord: 电源线
pad: 填充
workhorse: 重负荷机器
lid: 盖子
clicky: 滴答的
tactile: 触觉的,有触觉的
intervention: 介入,调停,妨碍
partially: 局部的,部分地
optical: 光学的
spike: 阻止
immune: 免疫
dang: 讨厌的
nail: 钉,使固定
avid: 贪婪的
enthusiast: 狂热者,热心家
Corel Linux : Corel corporation
coral: 珊瑚
outdoors: 户外
index finger: 食指
pull-cart: 拖车
obscure: 难懂的,晦涩的
slack: 松弛的,疏忽的,缓慢的
monty: 必定的事物,尤指赛马时必赢的马
appropriate: 恰当的
holy grail: 圣杯
fictional: 虚构的
patronimic: 教名
cohesion: 内聚力
ego: 自我,自负,自我意识
concensus:
compromise: 让步
deficiency: 缺陷,缺点,不足
adhere: 坚持,依附
recruit: 招聘,补充,聘用
bounty: 发给……奖金
overwhelm: 压倒,淹没,受打击
aggregator: 聚合器
appeal: 呼吁,恳求
recipe: 食谱,处方,秘诀
landscape: 风景,景色,山水
fiddle: 瞎搞,拉小提琴
dapper: 短小精悍的
drake: 公鸭
premium: 保险费,额外费用,奖金
lexmark: 利盟公司
stingy: 小气,吝啬
flock: 成群而行
democracy: 民主,民主政治
mash: 饲料
noob: newbie,新手
stumble: 踌躇,蹒跚
intrigue: 用诡计取得,激起……的兴趣
informative: 教育性的,有益的
polish: 优雅,精良
whopper: 弥天大谎
UV: 紫外线指数