美文网首页
《C Primer Plus》读书笔记(第三天)

《C Primer Plus》读书笔记(第三天)

作者: 道别1999 | 来源:发表于2019-07-10 23:32 被阅读0次

今天有些懒了@_@,再KTV从中午玩到了下午,午觉都没睡,注意力无法集中,学着学着手机就自动跳到手里了,学一点总结一点吧,现在真的困得不行

数据和C

- 示例程序

//程序清单3.1
#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");

    getchar();
    getchar();
    return 0;
}
  • scanf()函数用于读取键盘的输入
    • %f是指键盘输入的是浮点数
    • &weight表明把输入的值赋给weight变量

- 变量:可能会发生变化

- 常量:整个程序运行中没有变化

- 变量在程序中获取值的途径

  1. 赋值
int num;
num=2;
  1. 通过函数(如:scanf())获得值
int num;
scanf("%d",&num);
  1. 初始化变量:声明变量和赋值同时进行
int num=2;

相关文章

网友评论

      本文标题:《C Primer Plus》读书笔记(第三天)

      本文链接:https://www.haomeiwen.com/subject/prvkkctx.html