网站用户注册怎么做,有哪些做数据分析的网站,杭州建设企业网站的,h5页面制作报价根据C Primer Plus第五章进行学习 文章目录 循环简介基本运算符 1.赋值运算符#xff1a;2.加法运算符#xff1a;3.减法运算符#xff1a;-2.乘法运算符#xff1a;*总结 1.循环简介 如下代码可以体现不使用循环的局限性#xff1a;
#includestdio.h
#define AD… 根据C Primer Plus第五章进行学习 文章目录 循环简介基本运算符 1.赋值运算符2.加法运算符3.减法运算符-2.乘法运算符*总结 1.循环简介 如下代码可以体现不使用循环的局限性
#includestdio.h
#define ADJUST 7.31
int main()
{const double SCALE0.333;double shoe,foot;shoe9.0;footSCALE*shoeADJUST;printf(Shoe size (mens) foot length\n);printf(%10.1f %15.2f inches\n,shoe,foot);return 0;
} 1while循环
#includestdio.h
#define ADJUST 7.31
int main()
{const double SCALE0.333;double shoe,foot;printf(Shoe size (mens) foot length\n);shoe3.0;while(shoe18.5){footSCALE*shoeADJUST;printf(%10.1f %15.2f inches\n,shoe,foot);shoeshoe1.0; }printf(If the shoe fits,wear it.\n);return 0;
} 当 shoe18.5
中的内容就是要被重复的内容。花括号以及被花括号括起来的部分被称为块block。该循环一直持续到shoe19.0。 2.基本运算符
1.赋值运算符
bmw2002;
把值2002赋给变量bmw。也就是说左侧为一个变量名右侧是赋给该变量的值。赋值行为从右往左进行。
ii1;
该语句的意思是找出变量i的值把该值1然后赋给i。
在C语言中2002bmw;
类似这样的语句没有意义。因为在这里2002被称为右值只能是字面常量不能给变量赋值常量本身就是它的值。左侧必须是一个变量名。
2.加法运算符
printf(%d,420);
打印的是24而不是420。 int ex; int why; int zee; const int TWO2; why42; zeewhy; exTWO*(whyzee); 这里ex、why和zee都是可修改的左值它们可用于赋值运算符的左侧和右侧。TWO是不可修改的左值它只能用于赋值运算符的右侧。42是右值它不能引用某指定内存位置。另外why和see是可修改的左值表达式whyzee是右值该表达式不能表示指定内存位置。 3.减法运算符 -
下面语句表示把200.0赋给num: num224.0-24.0;
4.乘法运算符*
#includestdio.h
int main()
{int num1;while(num21){printf(%4d %6d\n,num, num*num);numnum1.0; }return 0;
}
该程序打印数字1~20及其平方。
1指数增长
一位统治者奖励学者学者指着棋盘说在第1个方格放1粒小麦第2个放2粒第3个放4粒第4个放8粒以此类推。下列程序计算出每个方格放几粒小麦。并计算了总数。
#includestdio.h
#define SQUARES 64
int main()
{const double CROP2E16;double current,total;int count1;printf(square grains total );printf(fractions of \n);printf( added grains );printf(world total\n); totalcurrent1.0;printf(%4d %13.2e %12.2e %12.2e\n,count,current,total,total/CROP);while(countSQUARES){countcount1;current2.0*current;totaltotalcurrent;printf(%4d %13.2e %12.2e %12.2e\n,count,current,total,total/CROP); }return 0;
} 下节继续学习基本运算符加油