2012年12月7日 星期五

c++之猜拳穩贏


include<iostream>
#include<cstdlib>
using namespace std;

main()
{int j;
cout<<"來猜拳(你穩輸)"<<endl;
cout<<"1=石頭,2=布,3=剪刀"<<endl;
cout<<"你出";
cin>>j;
switch(j)
{
case 1:
cout<<"我出布(笨)"  ;
break;
case 2:
cout<<"我出剪刀(憨)";
break;
case 3:
cout<<"我出石頭(呆)";
break;
default:
cout<<"亂出";
}

}

c++之數字大擺在前面


#include<iostream>
#include<cstdlib>
using namespace std;
main()
{
cout<<"請輸入兩個數字,我會把較大的數字放在前面"<<endl;
int a,b,c;
cin>>a>>b;
if(b>a)
{
c=b;
b=a;
a=c;
cout<<"magic!"<<a<<"  "<<b<<endl;
}
else if(a>b)
{
cout<<"magic!"<<a<<"  "<<b<<endl;
}
else
{
cout<<"magic!"<<a<<"="<<b<<endl;
}
}

c++之找出最大與最小數與位置


#include<iostream>
#include<cstdlib>
using namespace std;

main()
    {int i, x[10]={10,11,13,15,20,26,50,52,59,60};
     int max,min,maxd,mind;
min=x[0];
max=x[0];
cout<<"有10,11,13,15,20,26,50,52,59,60十個數"<<endl;
for(i=0;i<10;i++)
   {
if(x[i]>=max)
       {
max=x[i];
maxd=i;
    }
         
if(x[i]<=min)
{
min=x[i];
mind=i;


}
 
}
cout<<"The biggest number is"<<" "<<max<<" "<<"at"<<" "<<maxd+1<<endl;
cout<<"The smallest number is"<<" "<<min<<" "<<"at"<<" "<<mind+1<<endl;




}

c++之比大小


#include<iostream>
#include<cstdlib>
using namespace std;
int bigsmall(int x,int y)
{
if (x>y)
{
return x;
}
    else if (y>x)
{
return y;
}
}
int main()
{
int x,y,z;
cout<<"電腦將為您比大小"<<endl;
cout<<"請輸入第1個整數"<<endl;
cin>>x;
cout<<"請輸入第2個不一樣的整數"<<endl;
cin>>y;
z=bigsmall(x,y);
cout<<z<<"比較大";

}

c++之華氏換攝氏


#include<iostream>
#include<cstdlib>
using namespace std;
float temperature(float x)
{
return   x=(x-32)*5/9;
}
int main()
{
float x,y;
cout<<"請輸入華氏溫度" <<endl;
cin>>x;
y=temperature(x);
cout<<"攝氏溫度為"<<y<<endl;
}