c语言编程练习题:7-46 爬动的蠕虫
作者:yunjinqi   类别:    日期:2023-05-29 16:04:20    阅读:126 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    int N,U,D;
    int len=0;
    int direction=1;
    int count=0;
    if (scanf("%d",&N)!=EOF && scanf("%d",&U)!=EOF && scanf("%d",&D)!=EOF){
        while (len<N){
            if (direction==1){len = len+direction*U;}
            if (direction==-1){len = len+direction*D;}
            direction = direction*-1;
            count++;
            if (len>=N){break;}
        }
        printf("%d",count);
    }else{
        printf("something wrong when input N,U,D");
    }
    
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/171
上一篇:c语言编程练习题:7-45 找完数
下一篇:c语言编程练习题:7-47 二进制的前导的零