当前位置:网站首页>0 basic C language (1)
0 basic C language (1)
2022-06-26 20:20:00 【the best b】
Today we learn a simple change calculation .( In the future, there will be only main{} What's inside )
printf("100-23=%d\n",100-23);The result is zero 77, So how can we enter that number while the program is running 23, Then calculate the output .
int ptince=0;
printf(" Please enter the amount ( element ):");
scanf("%d",&price);
int change =100 - price;
printf(" Looking for you %d element .\n",change);The first line in the above line of code int price=0
This line defines a variable , The name of the variable is price, The type is int, The initial value is 0.
Variables for c Language is a place to store data , When we want to record the entered price, we need a variable to save the data , Only in this way can we participate in the following calculation .
The components of variables are generally < Type the name >< Variable name >; these two items. , for example :
int price;
int amount;
int price,amount;
The name of the variable is a kind of “ identifier ”, Identifier and python The string in is similar ,c Identifiers in languages can only consist of letters 、 Numbers and underscores , The number cannot appear in the first position , Of course c A keyword in a language cannot be used as an identifier .
c Reserved words in the language are :
auto,break,case,char,const, continue,default,do,double, else,enum,extern,float,for, goto,if,int,long,register,return,short,signed,sizeof,static, struct,switch,typedef,union, unsigned,void,volatile,while, inline,restrict.
When defining a variable, you can assign a value to a single variable in the definition, such as :
int price=0,amount=100;
price=0 It's a formula , there “=” Is an assignment operator , It means that you will “=” The value on the right is assigned to the variable on the left
Unlike math ,a=b To express relationships in mathematics , namely a and b The value of is the same , And in the c In language ,a=b Yes, it will b The value is assigned to a.
scanf Actually, it's equivalent to us python Medium input It is an output of content .
requirement scanf This function reads in the next integer , Then assign the read result to the variable price, When you run the program, you enter 23,scanf This data will be added to price in , What we see here & character , Is to represent the joining .
next int change =100-price;, Defines the second variable change, And the calculation is made. In this formula, there is a number that should be fixed 100, Then we can make it a constant and write it directly into the program
Define a constant :
const int AMOUNT=100
Then in the program, we can directly change the formula to
int change=AMOUNT-price;
This const It's a modifier , Add to int Used to add an invariant attribute to this variable , Once you add const The value of this attribute variable cannot be changed .
边栏推荐
- 0基础学c语言(3)
- MySQL - subquery usage
- 30. 串联所有单词的子串
- Muke 8. Service fault tolerance Sentinel
- Dynamic planning 111
- Wechat applet uniapp left slide delete with Delete Icon
- 问题解决:虚拟机无法复制粘贴文件
- Analysis on development technology of NFT meta universe chain game system
- 网上办理中金财富开户安全吗?
- String string is converted to jsonarray and parsed
猜你喜欢

Web resource preloading - production environment practice

Unity——Mathf. Similarities and differences between atan and atan2

Selection of database paradigm and main code

论数据库的传统与未来之争之溯源溯本----AWS系列专栏

Detailed explanation of shutter textfield

【推荐收藏】这8个常用缺失值填充技巧一定要掌握

c语言99乘法表

Feign remote call

IK word breaker

Wechat applet uniapp left slide delete with Delete Icon
随机推荐
Super VRT
Developer survey: rust/postgresql is the most popular, and PHP salary is low
飞天+CIPU体为元宇宙带来更大想象空间
mysql的充值问题
数据库范式和主码的选择
问题解决:虚拟机无法复制粘贴文件
String string is converted to jsonarray and parsed
云计算技术的发展与芯片处理器的关系
超分之VRT
Analysis on development technology of NFT meta universe chain game system
find_ path、find_ Library memo
Basic and necessary common plug-ins of vscade
Summary of several common UML diagrams
[most detailed] the latest and complete redis interview (70)
C# 练习。类列表加记录,显示记录和清空记录
郭明錤:苹果 AR / MR 头显是其有史以来设计最复杂的产品,将于 2023 年 1 月发布
案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:- 打开系统有欢迎界面,并显示可选择的选项- 选项1:记录比赛得分- 选项2:查看往届
515. find the maximum value in each tree row
西瓜书重温(七): 贝叶斯分类器(手推+代码demo)
Garbage collection mechanism of browser