C++簡單程式設計-1

來源:互聯網
上載者:User

標籤:position   info   idt   ant   com   mes   height   圖片   三次   

四、實驗結論

 

 

編程練習(1)

原始碼:

/*輸入 1~7 的整數,如果輸入的是 1~5,則輸出“workday. Let’s work hard”;如果輸入的是 6~7,則輸出“weekend. Let’s have a rest.” */#include<iostream>using namespace std;int main(){        int day;    cin>>day;    if(day>=1&&day<=5)        cout<<"workday. Let’s work hard.";    if(day==6||day==7)        cout<<"weekend. Let’s have a rest." ;    return 0;}

運行結果:

 

編程練習(2)

原始碼:

/*輸入一個整數,將各位元字反轉後輸出。(例如,輸入 365,輸出 563。樣本2-6的實現中, 5-6-3是分三次逐個輸出的,這裡要求把563作為一個數整體輸出。) */#include<iostream>using namespace std;int main(){        int n;    int m=0;    cin>>n;    while(n)    {        m=m*10+n%10;        n=n/10;    }    cout<<m;    return 0;}

運行結果:

 

五、實驗總結與體會

此次實驗依然用的是上學期所學的c語言的解題方式,只是為了熟悉c++的代碼格式和輸入輸出語句罷了。

 

 

 

 

 

 

 

 

C++簡單程式設計-1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.