<类型名称> <变量名称> ;bash
例如:函数
int price; int num,ani;
案例:spa
#include <stdio.h> /*就是一条预处理命令,它的做用是通知C语言编译系统在对C程序进行正式编译以前需作一些预处理工做。*/ //main函数是C语言的惟一入口 int main() { int price = 0; printf("请输入金额:"); scanf("%d",&price); int change = 100 - price ; printf("找您%d元\n",change); return 0; }
一、#include<stdio.h>
三、注释 四、{} 括号 五、声明 六、c语言自定义变量的要求 七、每一行结尾必须是英文下的分号(;)编译器 八、printf函数是向标准输出设备输出字符串 九、return语句 |
变量名是一种“标识符”。(所谓标识符,是为了区别这个和那个的不一样名字)
标识符由数字、字母、下划线组成
数字不能出如今首位
c的关键字(保留字)不能作标识符
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
除法运算中注意: 若是相除的两个数都是整数的话,则结果也为整数,小数部分省略,如8/3 = 2;而两数中有一个为小数,结果则为小数,如:9.0/2 = 4.500000。 取余运算中注意: 该运算只适合用两个整数进行取余运算,如:10%3 = 1;而10.0%3则是错误的;运算后的符号取决于被模数的符号,如(-10)%3 = -1;而10%(-3) = 1。 注:C语言中没有乘方这个运算符,也不能用×,÷等算术符号。
+=、-=、*=、/=、%=
#include <stdio.h> int main() { //定义小编兜里的钱 double money = 12 ; //定义打车回家的费用 double cost = 11.5 ; printf("小编能不能打车回家呢:"); //输出y小编就打车回家了,输出n小编就不能打车回家 printf( "%c", money>cost ? 'y' : 'n' ); return 0; }