ETH官方钱包

切換
舊版
前往
大廳
主題

C++上課筆記(1)

查理 | 2013-12-03 17:22:15 | 巴幣 0 | 人氣 307

#include <iostream>     //allow program to perform input and output
using namespace std; //引入using敘述式

int main()
{
cout<<"Hello"<<endl;     //輸入Hello  換行
system("pause");
return 0;
}


--------------------------------------------------------------------------------------------------------------------
輸入半徑計(jì)算圓面積
#include <iostream>
using namespace std;
#include <math.h>

int main()
{
    int r;
    double area;
    cout<<"輸入半徑"<<endl;
    cin>>r;
    area=M_PI*pow(r,2);
    cout<<"面積"<<area<<endl;
    
    system("pause");
    return 0;
}

--------------------------------------------------------------------------------------------------------------------------
輸入華氏溫度
轉(zhuǎn)換攝氏溫度

#include <iostream>
using namespace std;

int main()
{
    int fa;
    double ce;
    cout<<"華氏溫度:";
    cin>>fa;
    ce=((double)fa-32)*5/9;
    cout<<"攝氏溫度:"<<ce<<endl;
    system("pause");
    return 0;
}
--------------------------------------------------------------------------------------------------------------------------
梯形面積

#include <iostream>
using namespace std;

int main()
{
int up,base,h;
double area;
cout<<"上底,下底,高:";
cin>>up,base,h;
are=(up+base)*h/2;
cout<<"面積"<<area<<endl;
system("pause");
return 0;
}
--------------------------------------------------------------------------------------------------------------------------
輸入本金,利率
計(jì)算本利和
#include <iostream>
using namespace std;

int main()
{
int p;
double r,sum;
cout<<"本金"<<endl;
cin>>p;
cout<<"利率"<<endl;
cin>>r;
sum=p*(1+r);
cout<<"本利和"<<sum<<endl;
system("pause");
return 0;
}

創(chuàng)作回應(yīng)

更多創(chuàng)作