国王的小麦c语言编程

国王的小麦c语言编程,第1张

你已经给出了4种不同的编程。

// (1)

double p,i,t

p=1, t=1

i=1     唤核袜      和激         

while(i<64)

{   p=p*2

    t=t+p

    i++

}

// (2)

double p,i,t

i=1

for( i<64)

{  p=p*2

   t=t+p

   i++

}

// (3)

double p,i,t

for(i=1,t=1i<64i++)

{  p=p*2

   t=t+p

}

// (4)

double i,t

while(i<64)

{   t=t+pow(2,i)

  氏指  i++

}

// wheat.h

#include "stdio.h"

#define CELLS 64//格子数量

void main(void)

{

int index,each_cell,sum

double volume_wheat

for(index=1index<=CELLSindex++)

{

each_cell=2^(index-1)//每个格子麦子的数量

sum+=each_cell//统计麦子旦拍总数

}

volume_wheat=sum/模衫羡(1.42*108)

printf("麦子总数量:%d\n",sum)

printf("塌绝麦子的立方数:%lf\n",volume_wheat)

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12253652.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存