常量

 

常量是一种标识符,它的值在运行期间恒定不变。C 语言用 #define 来定义常量(称 为宏常量)。C++ 语言除了 #define 外还可以用 const 来定义常量(称为 const 常量)。

 

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6      int n;
 7     cout<<"n=";
 8     cin>>n;
 9     if (n>=0 && n<=100 &&n%2==0)
10        cout<<"n="<<n<<endl;
11     else
12        cout<<"The "<<n<<" is out of range!"<<endl;
13     return 0;
14 }

 

posted @ 2018-08-02 11:46  borter  阅读(185)  评论(0编辑  收藏  举报