标签:
#include <stdio.h> int main() { int count1 =1; do{ int count2 =0; ++count2; printf("\ncount1=%d count2=%d",count1,count2); count1++; }while (count1<=8); printf("\n count1=%d\n",count1); return 0; }
不等价于下面这个,尽管两个输出一样
#include <stdio.h> int main() { int count1 =1; do{ int count2 =0; ++count2; printf("\ncount1=%d count2=%d",count1,count2); }while (++count1<=8); printf("\n count1=%d\n",count1); return 0; }
详情见下面这个例子
#include <stdio.h> int main(void) { int count= 0; do{ int count =0; ++count ; printf("\n count=%d",count ); } while (++count<=8); printf("\n count =%d\n",count ); return 0; } /* count=0 count=0 count=1 dayin count=1<=8 count=0 count=1 dayin !! count=2<=8 ... count=0 count=1 dayin count=8<=8 count=0 count=1 dayin count=9 wo tiao count=9 shuchu 关键在于while 中的count 和do while 里面的不是一回事,while 使用的是那个外面的,do{}的count出了括号就死了 作用域就是这么回事,以大括号为界限,出来就死。 生存期就是,就活一轮,下一轮就重生 */
#include <stdio.h> float average(float x ,float y) { return (x+y)/2.0f; } int main (void) { float value1=0.0F; float value2=0.0F; float value3=0.0F; printf("Enter two floating-point values separated by blanks:\n"); scanf("%f %f",&value1,&value2); value3=average (value1,value2); printf("\n The average is:%f\n",value3); return 0; }/* 函数调用例子*/
#include <stdio.h> float average(float x ,float y);/* 也可以写做 float average (float ,float); */ int main (void) { float value1=0.0F; float value2=0.0F; float value3=0.0F; printf("Enter two floating-point values separated by blanks:\n"); scanf("%f %f",&value1,&value2); value3=average (value1,value2); printf("\n The average is:%f\n",value3); return 0; } float average(float x ,float y) { return (x+y)/2.0f; }
标签:
原文地址:http://www.cnblogs.com/xinqidian/p/5595799.html