2018年4月29日 星期日

c++ 直角三角形 米字

#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the isosceles triangle's cathetus:  ";  
int ca;
cin >> ca;
//isosceles triangle
for(int i=1;i<=ca;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
system("pause");
return 0;
}






#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the length: ";
int ca;
cin >> ca;
//the triangle
for(int i=ca;i>0;i--)//control the amount of *
{
for(int j=1;j<=i;j++)//control the row
{
cout<<"*";
}
cout<<endl;
}
system("pause");
return 0;
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "input the length: ";
int ca;
cin >> ca;
//triangle
for(int i=1;i<=ca;i++)//控制星星數 
{
for(int j=1;j<=ca;j++)//控制行數 
{
if( j<=(ca-i) )
{
cout << " ";
}
else
{
cout << "*";
}
}
cout <<endl;
}

}

















#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
cout << "Input the length: ";
int ca;
cin >> ca;
//triangle
for(int i=1;i<=ca;i++)
{
for(int j=1;j<=ca;j++)//控制行數 
{
if(j>=i)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout <<endl;

system("pause");
return 0;




2018年4月27日 星期五

//c++ 字母排序

#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
char s[10], t[10];int k[10], temp;
cout << "輸入十個英文字母(大小皆可): " <<endl;
//[input]
for(int i=0;i<10;i++){
cin >> s[i];
//cout << s[i];
k[i] = s[i];//字元→ASCII
//cout <<k[i]<<endl;
}
//[sort]
//選擇排序法
for(int i=0;i<10;i++)
{
for(int j=i+1; j<10; j++)
{
if(k[i]>k[j])
{
temp=k[i];
k[i]=k[j];
k[j]=temp;
}
}
}
//[output]
for(int i=0;i<10;i++)
{
t[i]=k[i];//ASCII→字元
cout << t[i];
}
system("pause");
return 0;
 }



//c++ 通話費計算

。題目:
有一家電信公司的計費方式:
每個月打800分鐘以下(不含800),每分鐘0.5元;
打800-1500分鐘時,所有電話費以95折計算;
打1500分鐘以上(不含1500),則通話費以8折計算。
請寫出一個程式,可由使用者輸入通話分鐘,程式即輸出其費用。


#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int t=0;
cout<<"請輸入通話時間(分鐘):";
cin>>t;
if(t<800)
{
if(t%2==0)
t*=0.5;
else
t=t*0.5+1;
cout<<"\n您的電話費是: "<<t<<"元\n";
}
else if(t<=1500)
{
t=t*95*5;
if(t%1000>0)
t=t/1000+1;
else
t/=1000;
cout<<"\n您的電話費是: "<<t<<"元\n"; 
}
else if(t>1500)
{
t=t*4;
if(t%10>0)
t=t/10+1;
else
t/=10;
cout<<"\n您的電話費是: "<<t<<"元\n";
}
}

2018年4月20日 星期五



「鈴!鈴!」
微風輕搖窗邊的晴天娃娃造型的風鈴,小二那年我父親送我的生日禮物。


在這溫度恰到好處的春日早晨,我坐於書桌前,緩緩地翻著小時的札記,從前的歡樂浮出了紙張,不斷地,不斷地,席捲著我的心頭。透過窗戶灑進來的晨陽,在玻璃的折與反,映射出了絢爛的霓虹世界,成了我回憶裡的夢幻。隨著風輕拂的花兒,華麗地揮灑著身上的露珠,與青草地彈奏曲曲柔和的旋律,繞於身旁。


彷彿,獨自乘著一艘小帆。徜徉於汪洋,隨著波浪的起舞享受自然的韻律。遠方,是天與海相互交織成的藝術,天的淡藍寬闊、海的深藍厚實,照映了彼此。海鷗們哼著宏亮的音譜,我想,亦是在讚嘆著眼前的美好吧!


美好,卻在這時離開,帶走了一片雲彩。天色逐漸暗沉,就連最後一絲光芒也毫不慰留,被烏雲給遮住了雙眼,漆黑一片。「隆!」「隆!」天空嘶吼著,好像要將天撕裂了一般,閃電也狠心地劃破天際。「不!不!」我雙手緊摀著耳朵,奮力地將眼皮闔起,整個人蜷曲一旁,窩在小帆的角落。心理,祈禱著,不斷地祈禱著這一切能馬上結束,希望甚麼都沒發生過。但是,錯了,無情的巨浪將我吞噬,連同小帆,成了他的美味佳餚,漸漸失去。


「鈴!鈴!」

原來是我睡著了,還好只是個夢啊!鈴聲再次搖響了我,將我拉出黑洞般的世界,要我記得眼前的現在,是溫暖。謝謝你,鈴。

20180420
00:32筆

2018年4月14日 星期六

// C++ 九九乘法表

//九九乘法表 
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
cout<<j<<"*"<<i<<'='<< setw(2) <<i*j<<' ';
}
cout<<endl;
}
return 0;
}








//法二
//以while迴圈

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int i=1,j=1;
while(i<10)
{
while(j<10)
{
cout<<i<<"x"<<j<<"="<<i*j;
cout<<"\t"<<i+1<<"x"<<j<<"="<<(i+1)*j;
cout<<"\t"<<i+2<<"x"<<j<<"="<<(i+2)*j;
j+=1;
cout<<endl;
}
j=1;
i+=3;
cout<<endl;
}
system("pause");
return 0;
}

//C++ 找出某範圍的所有質數

//找出到n範圍的所有質數 
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{ //使用者輸入 
int n;
cout << "Please input a number:" ;
cin >> n;

for(int i=2; i<=n; i++)
{
bool factor=false;
//找出質數 
for(int j=2; j<i; j++)
{
if(i%j==0)
factor=true;
}
//若為質數在印出 
if(factor==false)
{
cout << i <<endl;
}
}
system("pause");
return 0;
}









// C++ 質數判別

//質數判別 
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
int n;
cout << "Please input a number:" ;
cin >> n;
bool factor=false;
for(int i=2; i<n; i++)
{
if( n%i==0 ) factor=true;
}

if(factor)
cout << endl << "NO" ;
else 
cout << endl << "YES" ;

system("pause");
return 0;
}