单选题 C语言
题号 #2253128


下列程序的输出结果是(    )。
#included stdi0.h>
#included string.h>
void fun(int b[])
{  static int i=0;
do
{  b[i]+=b[i+1];
}while(++i<2);
}
main()
{  int k,a[5]={1,3,5,4,9};
fun(a);
for(k=0;k<5;k++)printf("%d",a[k]);
}

进入在线模考

参考答案

C

答案解析


本题考查do-while循环,在fun函数中,首先定义了静态变量i=0,do-while循环要实现的功能是以b[0]=b[0]+b[1],b[1]=b[1]+b[2],其他元素不变的规则重新给b数组赋值。在主函数中,通过调用fun函数,按上面的规则对数组a重新赋值,最后输出数组a。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考