数据和C语言

关键字—— int、short、long、unsigned、char、float、double、_Bool、_Complex;l

运算符——sizeof();

函数——scanf()


一、程序中的新元素 

#include<stdio.h>
int main(void)
{
    float weight;
    float value;
    printf("Are you worth your weight in platinum?\n");
    printf("Let's check it out.\n");
    printf("Please enter your weight in pounds:");
    scanf("%f",&weight);
    value = 1700.0*weight*14.5833;
    printf("Your weight in platinum is worth $%.2f.\n",value);
    printf("You are easily worth that! If platinum prices drop,\n");
    printf("eat more to maintain your value.\n");
    
    return 0;
}

1.代码中使用了一种新的变量float可以存储带小数的数字

2.为了打印新的变量,在printf()中使用%f来处理浮点值。%.2f中的.2用于精确控制输出,指定输出的浮点数只显示小数点后面两位。

3.scanf()函数用于独缺键盘的输入


二、数据类型关键字

浮点数:注意,在一个值后面加上一个小数点,该值就成为一个浮点值。

计算机把浮点数分成小数部分和指数部分来表示,而且分开存储这两部分。

C语言基本数据类型:

1. short int类型占用的存储空间可能比int类型少,常用于较小数值的场合以节省空间。

2. long int或long占用的存储空间可能比int多,适用于较大数值的场合。与int类似,long是有符号类型。

3. long long int 该类型至少占64位

4. unsigned int 或unsigned 只适用于非负值的场合。16位unsigned int 允许的取值范围是0~65535。

打印short、long、longlong、和unsigned类型

打印unsigned int类型的值,使用%u转换说明

打印long类型的值,使用%ld转换说明

%lx表示以16进制格式打印long类型整数

%lo表示以8进制格式打印long类型整数

对于short类型

%hd表示以十进制显示short类型整数,%ho表示以八进制显示short类型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值