习题6.3

来源:互联网 发布:淘宝网注册企业店铺 编辑:程序博客网 时间:2024/06/10 06:17
#include <stdio.h>#include <stdlib.h>int main(){    int x=1,find=0;    while (!find)    {        if(x%2=1&&x%3=2&&x%5=4&&x%6=5&&x%7=0)        {             printf("x=%d\n",x);             find =1x++;        }    }    return 0;}

改正如下:

#include <stdio.h>#include <stdlib.h>int main(){    int x,find=0;    for (x=1;!find;x++)    {        if(x%2==1&&x%3==2&&x%5==4&&x%6==5&&x%7==0)        {             printf("x=%d\n",x);             find =1;        }    }    return 0;}

结果为:
心得体会:
1:第一题中逻辑错误,改为for语句后要注意=改为==
2:第一题中x++不能和前面两个语句在同一个括号中。

原创粉丝点击