早教吧 育儿知识 作业答案 考试题库 百科 知识分享

编程:计算S=1+2+4…+2n,当S超过10时,求n的最小值及s的值.

题目详情
编程:计算S=1+2+4…+2n,当S超过10时,求n的最小值及s的值.
▼优质解答
答案和解析
计算S=1+2+4…+2n,当S超过10时,求n的最小值及s的值.
程序如下:
#include "stdio.h"
main()
{ int s, n, x;
s=1; n=1,x=1;
while (s<=10)
{
x=x*2;
s=s+x;
n++;
}
printf ("s=%d,n=%d",s,n);
}