C++入門經典第一章程式設計專案

千歲憂發表於2018-08-19

1.

#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
    int a, b;
    cout << "請輸入兩個任意整數:\n";
    cin >> a >> b;
    cout << "兩者和為:" << a + b << "\n";
    cout << "兩者積為:" << a * b << "\n";
    cout << "這是程式結尾\n";
}

2.

#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
    cout << "************************************************************\n\n";
    cout << "      ccc        sss    !!\n";
    cout << "     c   c      s       !!\n";
    cout << "    c            sss    !!\n";
    cout << "     c   c          s       !!\n";
    cout << "        cc         sss    0 0 \n";
    cout << "\n";
    cout << "************************************************************\n";
    cout << "成功完成!!!";
}

3.

#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
    int a, b, c;
    cout << "請輸入25美分硬幣數:\n";
    cin >> a;
    cout << "請輸入10美分硬幣數:\n";
    cin >> b;
    cout << "請輸入5美分硬幣數:\n";
    cin >> c;
    cout << "一共是:" << a * 25 + b * 10 + c * 5 << "美分\n";
}

4.

#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
    int  t;
    double g,h;
    g = 9.8;
    cout << "請輸入墜落時間:\n";
    cin >> t;
    h = g * t*t;
    cout << "自由落體距離是:\n"<<h/2;
}

5.

#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
    char X;
    cout << "請輸入字母:\n";
    cin >> X;
    cout << X << X << X << X;
}

相關文章