#include <iostream> #include <fstream> using namespace std; char* encode(char*); char* decode(char*); int main(void) { char ch,str[80]; cout<<"請輸入字串:"; gets(str); cout<<"您要 1)加密 2)解密 :"; cin>>ch; if(ch == '1') { cout<<"After encode : "; cout<<encode(str); } else if (ch == '2') { cout<<"After decode :"; cout<<decode(str); } else cout<<"Unknown input"; return 0; } char* encode(char *str) { char *r=str; while(*str) { *str = *str + 13; str++; } return r; } char* decode(char *str) { char *r=str; while(*str) { *str = *str - 13; str++; } return r; }
#include <iostream> #include <string.h> using namespace std; void exclude(char*,char*); int main(void) { char str1[] = "what a wonderful world!"; char str2[] = "wonderful"; //要去除的文字 exclude(str1,str2); cout<<str1<<endl; return 0; } void exclude(char *s1,char *s2) { int i, s2_len = strlen(s2); for(i=0; i<(int)strlen(s1) - s2_len; i++){ if(!strncmp(s1+i, s2, s2_len)){ strcpy(s1+i, s1+i+s2_len); i--; } } }
#include <iostream> #define CPU "Central Processing Unit" //定義字串 #define PI 3.14159 //定義常數 using namespace std; int main(void) { cout<<"CPU is short for "<<CPU<<endl; cout<<"π= "<<PI<<endl; return 0; }
#include <iostream> #define SWAP(x,y,t) (t = x, x = y, y = t) //定義巨集 using namespace std; int main(void) { int x=3,y=4,temp; SWAP(x,y,temp); //呼叫巨集 cout<<"x = "<<x<<" y = "<<y<<endl; return 0; }
#include <iostream> #define add(x,y) ((x)+(y)) #define minus(x,y) ((x)-(y)) #define multiply(x,y) ((x)*(y)) #define divide(x,y) ((double)(x)/(y)) using namespace std; int main(void) { int a,b; char choice; cout<<"請輸入您的計算式:"; cin>>a>>choice>>b; switch(choice) { case '+': cout<<a<<"+"<<b<<"="<<add(a,b); break; case '-': cout<<a<<"-"<<b<<"="<<minus(a,b); break; case '*': cout<<a<<"*"<<b<<"="<<multiply(a,b); break; case '/': cout<<a<<"/"<<b<<"="<<divide(a,b); break; default: break; } return 0; }
#include <iostream> //插入標頭檔 using namespace std; int main() //main函式 { //程式區塊開始 int number; //宣告變數 number=0; cout<<number<<endl; //將變數輸出,演示變數宣告成功 return 0; } //程式區塊結束
相信大家都知道電腦裡可以「跑」的東西叫程式吧!!!(廢話)那大家都知道任何的資料(包括程式、圖檔等...)存放在電腦底層都是0和1吧!!因為如此一來只須找到一種物質能輕易保持兩種型態就可以拿來做為電腦的晶片了,事情當然是越簡單越好嘛!因為廠商很懶...不是,是因為越簡單越好控制,也可以越做越小...哀,扯太遠了,拉回來。好,所以現在我們知道程式是
由1和0所組成...ㄟ,不對阿,我看駭都可以打一些程式碼...不用廢話,就是1跟0,我知道,一定沒人看得懂1、0阿,所以我們假設有一對資料長這樣:
由1和0所組成...ㄟ,不對阿,我看駭都可以打一些程式碼...不用廢話,就是1跟0,我知道,一定沒人看得懂1、0阿,所以我們假設有一對資料長這樣: