C

笔记

<stdio.h>
#include<stdio.h>
<math.h>
#include<math.h>
输出

printf()

%d & %f
  1. 整数值用 %d 输出, 浮点数用 %f 输出
  2. 整数值是指整数之间的运算,其结果也是整数;浮点数值是指浮点数之间的运算,其结果是浮点数。
  3. 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()
  1. 功 能: 执行格式化输入
  2. 输入时是 "%lf" 而不是"%f"
scanf("%d%d%d",&a,&b,&c); 
const

const 声明常数

const double pi = acos(-1.0);
floor()
  1. 向下取整
  2. double floor(double x)
if 语句

if(condition) statement1; else if(condition2) statement3; else statement2;

if(condition){
    statement1;
}
else if(condition2){
    statement3;
}
else{
    statement2;
}
短路

C语言中的逻辑运算符都是短路运算符。一旦能够确定整个表达式的值, 就不再继续计算。

注释
  1. 多行注释 /* */
  2. 单行注释 //
break & continue
  1. continue 指继续for循环中的下一个循环
  2. 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值