# include <iostream>
using namespace std;
int main(){
int a = 2;
int b = 5;
//变量赋值为整数
cout<< "a="<<a <<" ";
cout<< "b="<<b << endl;
b = b + 3;
cout<< "a="<<a <<" ";
cout<< "b="<<b;
}
数据类型 int表示整形
变量的声明
格式:数据类型 变量名1,变量名2,………;
int a,b,c……(伪代码)
- 先声明、后赋值
同类型的变量可以一起声明int a;
int b;
a = 2;
b = 5;
int a,b
- 声明时,同时赋值
int a = 2, b = 5;
声明时直接赋值
# include <iostream>
using namespace std;
int main(){
const float g = 9.78;
int t ;
float v;
t=10;
v = g*t;
cout<<"落地速度" <<v <<"米/每秒"<< endl;
}
常量的定义
格式:condt 数据类型 变量名1,变量名2……;
const int a,b,c……;(伪代码)
# include <iostream>
using namespace std;
+ const float g = 9.78;
int main(){
- const float g = 9.78;
int t ;
float v;
t=10;
v = g*t;
cout<<"落地速度" <<v <<"米/每秒"<< endl;
}
#include <iostream>
using namespace std;
int main()
{
int i ;
i=0;
i=i+1;
cout<<i<<endl;
i=i+1;
cout<<i<<endl;
i=i+1;
cout<<i<<endl;
i=i+1;
cout<<i;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int m;
float r;
m=9800;
r=m*0.04;
cout<<r<<endl;
}
5/2的值是2,不是2.5。而是5.0/2或5/2.0的值是2.5