Apr 7, 2014
Technology###Programming In C
intermediate: 中级的
hereby: 特此
scary: 恐慌的,提心吊胆的
de facto (法),事实上的
span: 跨越
interpreted: 可交互的
fanatic: 狂热者
novice: 新手,入门者
concrete: 实际的
prime number: 素数,质数
ternary: 三重的,三元的
intrusive: 侵入的,打扰的
grind: 磨难,磨碎,折磨
confessed: 坦白的
scary: 提心吊胆的,胆小的
apropos: 恰好的
grasp: 掌握
instalment: 分期付款的
gibberish: 乱语,快速而不清楚的话语
condense: 电容器
Apr 7, 2014
Technology###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.
Apr 7, 2014
Technology###Full Circle 3
stunning: 令人惊奇的事物
reveal: 揭露
footrest: 搁脚物
fusion: 融化
compiz+beryl = Compiz Fusion
trawl: 用拖网捕鱼
Apr 6, 2014
Technology###Full Circle 2
Things to be done:
- Page 3, Visit linuxgeekery?
- Page 4, OpenMOKO, its recent status. Try to visit www.linuxinsider.com
- Page 5, UbuntuHomeServer? www.ubuntuhomeserver.org
- Page 16, try VPN, use VPN to reach back home.
- Page 25, What is GEDCOM?
- Page 27, What is LDS church?
- Page 28, Still , try Gramps.
- Page 29, ipod support on Ubuntu, libgpod. amaroK
- Page 31, try flock, democracy player, songbird, inkscape
- Page 34, try game tremulous.
- Page 36, try ubuntustudio theme.
- Page 37, try to install these applets and integrate them with awesome.