C语言,求过程?

C语言,求过程?,第1张

void reverse(int a[ ],int n)

{ int i,t

for(i=0i<n/2i++)

{ t=a[i]a[i]=a[n-1-i]a[n-1-i]=t}

}

第一次执行时 a[0] 和 a[7]对调 1和8对调

第二次执行是 a[1] 和袭坦 a[6]对调 2和7对野升调

结果为87654321 9 10

后4位相加颂禅老为22

A 本题并不是将整个数组中镇晌的内容逆置,而是逆置前8个元素。逆置后的数组为:8,7,6,5,4,3,2,1,9,10通过for循环计算御余锋毁凳b[6]+b[7]+b[8]+b[9]即2+1+9+10=22

就是选A呀

看下程序运行结果,不懂的地方可以问我哈。

#include <iostream>孝液孙

#include <stdio.h>

#include <math.h>

#include <iomanip>

using namespace std

void reverse(int  a[ 巧链埋启],int n)

int  i,t

for(i=0i<n/2i++)

t=a[i]

a[i]=a[n-1-i]

a[n-1-i]=t

}

}

main()

{

int  b[10]={1,2,3,4,5,6,7,8,9,10} int i,s=0

reverse(b,8)

for(i=6i<10i++){

s+=b[i]

printf("b[%d]=%d\n",i,b[i])

}

printf("%d\n",s)

}


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

原文地址: https://outofmemory.cn/yw/12446172.html

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

发表评论

登录后才能评论

评论列表(0条)

保存