202609261806_《循环/for/while》

//例一
int main() {
int n = 256; do { printf("%d\n", n); n = n / 2; } while (n >= 1 && n % 2 == 0); return 0; }

//方法二

int main()
{
  int n = 199;

  for (int i = 1; i <= n; i *= 2)
{
    printf("%d\n", i);
}

return 0;
}
 
//例二
int main()
{
  const double h_hill = 8848430.0;
  double t_paper = 0.5;
  int count = 0;

while (t_paper < 8848430) //注意: 非“<=“, t_paper:25 , h_hill:16777216.0
{
  t_paper = t_paper * 2;
  ++count;
}

  printf("折叠次数:%d\n", count);
  printf("最终高度:%.1f mm\n", t_paper);

  return 0;
}
 

 

posted @ 2026-09-26 18:06  Coca-code  阅读(2)  评论(0)    收藏  举报