C++ 入門指南 V2.00 - 單元 6 範例及練習程式碼



exercise0601.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a = 2;
   int b = 8;
    
   cout << "a + b = " << a + b << endl;
   cout << "a - b = " << a - b << endl;
   cout << "a * b = " << a * b << endl;
   cout << "a / b = " << a / b << endl;
   cout << "a % b = " << a % b << endl;
    
   return 0;
}
 
/* 檔名: exercise0601.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0602.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a;
   int b;
    
   cin >> a;
   cin >> b;
    
   cout << "a + b = " << a + b << endl;
   cout << "a - b = " << a - b << endl;
   cout << "a * b = " << a * b << endl;
   cout << "a / b = " << a / b << endl;
   cout << "a % b = " << a % b << endl;
    
   return 0;
}
 
/* 檔名: exercise0602.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0603.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   double a;
   double b;
    
   cin >> a;
   cin >> b;
    
   cout << "a + b = " << a + b << endl;
   cout << "a - b = " << a - b << endl;
   cout << "a * b = " << a * b << endl;
   cout << "a / b = " << a / b << endl;
    
   return 0;
}
 
/* 檔名: exercise0603.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0604.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a = 1;
    
   cout << "++a = " << ++a << endl;
   cout << "++a = " << ++a << endl;
   cout << "++a = " << ++a << endl;
   cout << "++a = " << ++a << endl;
   cout << "++a = " << ++a << endl;
   cout << "++a = " << ++a << endl;
   cout << "++a = " << ++a << endl;
    
   return 0;
}
 
/* 檔名: exercise0604.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0605.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
    string a("*");
    
    cout << a << endl;
    cout << a + a << endl;

    return 0;
}
 
/* 檔名: exercise0605.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0606.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a = 1;
   int b = 2;
    
   cout << (a > b ? "a is bigger" : "b is bigger") << endl;

   return 0;
}
 
/* 檔名: exercise0606.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

exercise0607.cpp


#include <iostream>
 
using namespace std;
 
int main(void) {
   int a;
   int b;
    
   cin >> a;
   cin >> b;
    
   cout << (a > b ? "a is bigger" : "b is bigger") << endl;

   return 0;
}
 
/* 檔名: exercise0606.cpp 
   作者: Kaiching Chang 
   時間: 2014-5 */

the end

沒有留言: