笔记
<stdio.h>
#include<stdio.h>
<math.h>
#include<math.h>
输出
printf()
%d
& %f
- 整数值用
%d
输出, 浮点数用%f
输出 - 整数值是指整数之间的运算,其结果也是整数;浮点数值是指浮点数之间的运算,其结果是浮点数。
8/5.0
=>8.0/5.0
;8.0/5
=>8.0/5.0
printf("%d\n", 8/5); //1
printf("%.1f\n", 8.0/5.0); //1.6
printf("%.2f\n", 8.0/5.0); //1.60
scanf()
- 功 能: 执行格式化输入
- 输入时是
"%lf"
而不是"%f"
scanf("%d%d%d",&a,&b,&c);
const
用 const
声明常数
const double pi = acos(-1.0);
floor()
- 向下取整
double floor(double x)
if
语句
if(condition) statement1; else if(condition2) statement3; else statement2;
if(condition){
statement1;
}
else if(condition2){
statement3;
}
else{
statement2;
}
短路
C语言中的逻辑运算符都是短路运算符。一旦能够确定整个表达式的值, 就不再继续计算。
注释
- 多行注释
/* */
- 单行注释
//
break
& continue
- continue 指继续for循环中的下一个循环
- break 指直接跳出for循环
Questions
Q1
printf("%d\n", 11111*11111); //123454321
printf("%d\n", 111111*111111); //-539247567
printf("%d\n", 111111111*111111111); //1653732529
printf("%.1f\n", 11111.0*11111.0); //123454321.0
printf("%.1f\n", 111111.0*111111.0); //12345654321.0
printf("%.1f\n", 111111111.0*111111111.0); //12345678987654320.0
printf("%d\n", sqrt(-10)); //-272632256
printf("%f\n", sqrt(-10)); //nan
printf("%d\n", 1.0/0.0); //-272632256
printf("%f\n", 1.0/0.0); //inf
printf("%d\n", 0.0/0.0); //-272632256
printf("%f\n", 0.0/0.0); //nan
printf("%d\n", 1/0); //-272632256
printf("%f\n", 1/0); //0.000000
Q2
int a, b;
scanf("%d%d", &a, &b); //12 2
printf("%d %d\n", a, b); //12 2
int a, b;
scanf("%d%d", &a, &b); //12 s
printf("%d %d\n", a, b); //12 32766