鹿城实验中学2018.2
2018-02-06 08:00:00 - 2018-06-30 00:00:00 排名
已结束
#include<bits/stdc++.h>
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
//结果发现char的最大最小值输出为奇怪的符号,最后对char输出强制转化为int类型后即可得到结果。
cout << "char min:" << (int)numeric_limits<char>::min() << "\t\t\t max:" << (int)numeric_limits<char>::max() << endl;
//cout << "min:" << numeric_limits<char>::min() << " max:" << numeric_limits<char>::max() << endl;
cout << "short min:" << numeric_limits<short>::min() << "\t\t max:" << numeric_limits<short>::max() << endl;
cout << "int min:" << numeric_limits<int>::min() << "\t\t max:" << numeric_limits<int>::max() << endl;
cout << "long min:" << numeric_limits<long>::min() << "\t\t max:" << numeric_limits<long>::max() << endl;
cout << "long long min:" << numeric_limits<long long>::min() << "\t max:" << numeric_limits<long long>::max() << endl;
cout << "float min:" << numeric_limits<float>::min() << "\t\t max:" << numeric_limits<float>::max() << endl;
cout << "double min:" << numeric_limits<double>::min() << "\t\t max:" << numeric_limits<double>::max() << endl;
cout << "long double min:" << numeric_limits<long double>::min() << "\t\t max:" << numeric_limits<long double>::max() << endl;
cout << "unsigned min:" << numeric_limits<unsigned>::min() << "\t\t\t max:" << numeric_limits<unsigned>::max() << endl;
return 0;
}
数学运算符 | C++运算符 | 举例 |
+ | + | c = 4+3,c的值为7 |
- | - | c = 4-3,c的值为1 |
* | * | c = 4*3,c的值为12 |
/ | / | 若两边都是整数参与运算那么结果是整数,只要有一边是实数,结果就为实数, 例:c = 4/3,c的值为1,c=4/3.0,c的值为1.3 |
求余数 | % | c = 4%3,c的值为1 |
求绝对值 | abs | a=abs(-6),a的值为6 |
次方 | pow(x,y) | a=pow(2,4),a的值为2的4次方即16 |
平方根 | sqrt() | c=sqrt(9),c的值为3.0,要包括cmath库 |
类型 | C++类型 | 定义举例 | printf语句中的格式 | 备注 |
整型 | int | int x | d | 10位的数 |
长整型 | long long | long long x | lld | 20位的数 |
单精度 | float | float x | f | 有效数字7位 |
双精度 | double | double x | lf | 有效数字19位,常用这种 |
长双精度 | long double | long double x | Lf 或 llf | 有效数字更长 |
实数一般定义为double类型。
c语言输出x带3位小数,可以使用 printf(“%0.3lf”,x);
printf("%0.*lf",y,x) 表示输出x时保留y位小数(*会用后面的y替代)。
关系运算符 | 意思 |
> | 大于 |
>= | 大于等于 |
< | 小于 |
<= | 小于等于 |
== | 等于 |
!= | 不等于 |
! | 否,真变假,假变真,即取反 |
|| | 或者,两边只要有一个位真就为真 |
&& | 并且,两边同时为真才为真 |
函数使用:
x^y的pow(x,y) 四舍五入round(x)
cout<<“Hello World!”<<endl; // 编译运行
int = + - * /
double %
完成作业的请移步基础题库