Saturday, September 26, 2009

線上免費下載

在做網頁時,常常需要很多按鈕圖片,如果平常沒有做好蒐集的工作,往往在要用的時候找不到好用的愛紐圖片。

如果你有以上問題可以到 http://365icon.com/ 這個網站來尋寶。除了圖資豐富外,畫質都相當不錯喔!

寄件者 Blogger
我就挑選很懷舊的"瑪莉歐"的套圖吧!


寄件者 Blogger
這些圖片質感都很不錯,真是個值得推薦的好網站!


寄件者 Blogger

線上免費下載ICON圖檔的網站

常常會有以下問題:
  1. 總覺得自己桌面的icon很醜。
  2. 當使用RocketDock等工具時,icon放大影像都會模糊掉。
  3. 線上下載的套裝icon沒有提供所有應用程式的套圖,總覺得有點缺憾。
如果你有以上的問題,那你可以到http://www.iconfinder.net/找尋你喜歡的icon囉!

寄件者 Blogger
哇! 好多豐富的icon啊! 快去用用看吧!

寄件者 Blogger

Wednesday, September 23, 2009

數字系統(十進制轉二、八、十六進制)

很久沒練習了C的語法了,心血來潮就寫了這篇。

BinarySystem()是將二進制數字轉換成十進制
第13行:Bin[i]-48是因為Bin是字元(char),所以要透過ASCII(美國資訊交換標準碼)轉換成數字。

#include<iostream>
#include<conio.h>
void BinarySystem(){
char Bin[11];
int LastDigit=0;
int Decimal=0, Weight=1;
printf("請輸入二進制數字(最多10位元):");
scanf("%s", Bin);
while(Bin[LastDigit]!='\0')
LastDigit++;
LastDigit--;
for(int i=LastDigit; i>=0; i--){
Decimal=Decimal+(Bin[i]-48)*Weight;
Weight*=2;
}
printf("二進制數字:%s\n十進制數字:%d\n", Bin, Decimal);
}

OctalSystem()是將八進制數字轉換成十進制

void OctalSystem(){
char Bin[11];
int LastDigit=0;
int Decimal=0, Weight=1;
printf("請輸入八進制數字(最多10位元):");
scanf("%s", Bin);
while(Bin[LastDigit]!='\0')
LastDigit++;
LastDigit--;
for(int i=LastDigit; i>=0; i--){
Decimal=Decimal+(Bin[i]-48)*Weight;
Weight*=8;
}
printf("八進制數字:%s\n十進制數字:%d\n", Bin, Decimal);
}

HexSystem()是將十六進制數字轉換成十進制
第43行:因為十六進制有A、B、C、D、E、F因此需要更改ASCII轉換成數字的參數

void HexSystem(){
char Bin[11];
int LastDigit=0;
int Decimal=0, Weight=1;
printf("請輸入十六進制數字(最多10位元,字母請大寫):\n");
scanf("%s", Bin);
while(Bin[LastDigit]!='\0')
LastDigit++;
LastDigit--;
for(int i=LastDigit; i>=0; i--){
if(Bin[i]>=65)
Decimal=Decimal+(Bin[i]-55)*Weight;
else
Decimal=Decimal+(Bin[i]-48)*Weight;
Weight*=16;
}
printf("十六進制數字:%s\n十進制數字 :%d\n", Bin, Decimal);
}

選擇轉換模式

void SelectMode(){
char Mode;
printf("選擇模式:A.二進位; B.八進位; C.十六進位;\n");
Mode=_getche();
printf("\n");
if(Mode=='A')
BinarySystem();
else if(Mode=='B')
OctalSystem();
else if(Mode=='C')
HexSystem();
else{
printf("沒有這種模式!\n");
}
}

主程式,利用do-while的方式重複做。

int main(){
char Choose;
printf("數字系統:轉換成十進位");
do{
SelectMode();
printf("是否要重作?(Y/N)\n");
Choose=_getche();
printf("\n");
}while(Choose=='Y' || Choose=='y');
system("pause");
return 0;
}

因為當中有十六進制,所以採用字元(char)的放式儲存變數。
雖然比使用數學運算式來的耗資源,但是用字元(char)更方便看懂計算過程。

Monday, September 21, 2009

最小公倍數(LCM)

最小公倍數(Least Common Multiple, LCM)是兩個整數共有倍數中最小的一個。

計算最小公倍數時,通常會藉助最大公因數(gcd/hcf)來輔助計算。
公式如下:


計算最小公倍數
請輸入兩個數字:
1st: 55
2nd: 44
最大公因數為:11
最小公倍數為:220
請按任意鍵繼續 . . .

#include <iostream>
using namespace std;
int GCD(int a, int b){
if(a%b){
return GCD(b, a%b);
}
else{
return (b);
}
}
int main(){
int x, y, gcd, lcm;
cout << "計算最小公倍數\n" << "請輸入兩個數字:\n";
cout << "1st: ";
cin >> x;
cout << "2nd: ";
cin >> y;
gcd=GCD(x,y);
cout << "最大公因數為:" << gcd << endl;
lcm=x*y/gcd;
cout << "最小公倍數為:" << lcm << endl;
system("Pause");
return 0;
}

Friday, September 11, 2009

最大公因數(GCD)

最大公因數(Greatest Common Divisor,簡寫為G.C.D.;或Highest Common Factor,簡寫為H.C.F.)
這是很多程式的入門練習題,尤其是使用遞迴呼叫(recursive call)的方式。

如何找出兩個數的最大公因數呢?
最常見的方式是輾轉相除法---輾轉相除法,又名歐幾里得演算法(Euclidean algorithm)乃求兩個正整數之最大公因數的演算法。
這是已知最古老的演算法, 其可追溯至前300年。首次出現於歐幾里得的《幾何原本》(第VII卷,命題i和ii)中,而在中國則可以追溯至東漢出現的《九章算術》。這演算法並不需要把二數作質因數分解。

以下分別以C++實作這兩個方法:

《九章算術》
計算最大公因數
請輸入兩個數字:
1st: 96
2nd: 72
96>72, 96-72=24
24<72, 72-24=48
24<48, 48-24=24
24=24, 最大公因數為:24
請按任意鍵繼續 . . .

#include <iostream>
using namespace std;
int fun(int a, int b)
{
if(a>b)
{
cout << a << ">" << b << ", " << a << "-" << b << "=" << a-b << endl;
return fun(a-b,b);
}
else if(a<b)
{
cout << a << "<" << b << ", " << b << "-" << a << "=" << b-a << endl;
return fun(a,b-a);
}
else
{
cout << a << "=" << b << ", ";
return (a);
}
}
int main(){
int x,y;
cout << "計算最大公因數\n" << "請輸入兩個數字:\n";
cout << "1st: ";
cin >> x;
cout << "2nd: ";
cin >> y;
cout << "最大公因數為:" << fun(x,y) << endl;
system("Pause");
return 0;
}


《幾何原本》
計算最大公因數
請輸入兩個數字:
1st: 96
2nd: 72
96>72, 96%72=24
72%24=0, 最大公因數為:24
請按任意鍵繼續 . . .

#include<iostream>
using namespace std;
int fun(int a, int b){
if(a%b){
cout<<a<<">"<<b<<", "<<a<<"%"<<b<<"="<<a%b<<endl;
return fun(b, a%b);
}
else{
cout<<a<<"%"<<b<<"=0, ";
return (b);
}
}
int main(){
int x,y;
cout<<"計算最大公因數\n"<<"請輸入兩個數字:\n";
cout<<"1st: ";
cin>>x;
cout<<"2nd: ";
cin>>y;
if(x>y)
cout<<"最大公因數為:"<<fun(x,y)<<endl;
else if(x<y)
cout<<"最大公因數為:"<<fun(y,x)<<endl;
else
cout<<"最大公因數為:"<<x<<endl;
system("Pause");
return 0;
}