首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p~n-1(p<n-1)的数组元素平移到数组的前面。 例如,一维数组中的原始内容为1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p~n-1(p<n-1)的数组元素平移到数组的前面。 例如,一维数组中的原始内容为1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
admin
2010-11-26
37
问题
请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p~n-1(p<n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, P的值为6。移动后,一维数组的内容应为7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
[试题源程序]
#inciude <stdio.h>
#define N 80
void fun(int *w, int p, int n)
{
}
main()
{
int a[N]=(i, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
int i, P, n=15;
printf("The original data:\n");
for(i=0; i<n; i++)
printf("%3d", a
);
printf("\n\nEnter p: ");
scanf("%d", &p);
fun(a, P, n);
printf("\nThe data after moving:\n");
for(i=0; i<n; i++)
printf("%3d", a
);
printf("\n\n");
}
选项
答案
void fun(int *w, int p, int n) { int i, J, t; for(i=p; i<=n-i; i++) { t=w[n-1]; for(j=n-2; j>=0; j--) w[j+1]=w[j]; w[0]=t; } }
解析
转载请注明原文地址:https://jikaoti.com/ti/dBkiFFFM
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
下列有关利率的说法,错误的是()。
张某以请客为名用酒将高某灌醉,然后扶高某到一偏僻无人处,将高某的钱包(内有人民币5000元)拿走。张某的行为构成()。
某县公安局民警甲在一次治安检查中被乙打伤,公安局认定乙的行为构成妨碍公务,据此对乙处以200元罚款。甲认为该处罚决定过轻。下列哪种说法是正确的?()
国家机构是我国宪法的主要内容之一。下列有关国家机构的说法正确的是()。
近年来,我国极地科学考察不断取得优异成绩,目前已在南北极建立了四个科学考察平台.在北极建立的是()。
张大来的原户籍所在地在杨村,1994年张大来从杨村开出迁住证,迁往李村。但在李村登记前,张大来得病,在县城医院住院一年零三个月。病愈后张大来前往北京市打工,并在某区办理了暂住证,居住期限为6个月,现住在某区某街道某号。现问,张的住所应确定为何处?()
王某现年17岁,高二学生,平时创新能力极强,其研究创造的一个小发明获得专利,并且经济价值较高。专利权的申请、使用和由此所获取的收人的处理一概由王某的父亲予以安排,王某的父亲从事的下列各种行为中,违背了《民法通则》规定的监护责任的是()。
行政机关公开政府信息的原则不包括()。
华氏度和摄氏度均是测量温度的单位,摄氏度规定水的冰点温度为0度,沸水温度为100度:华氏度规定水的冰点为32度,沸点为212度。某时刻华氏度比摄氏度数值上高60度,则该时刻为:
一批树苗,按下列原则分给各班栽种:第一班取走100棵文取走剩下树苗的,第二班取走200棵又取走剩下树苗的,第三班取走300棵又取走剩下树苗的,依此类推,第三班取走树苗100i棵又取走剩下树苗的,……,直到取完为止。最后各班所得树苗都相等。试问共有几个班?
随机试题
上下:左右
方法
翼外肌功能亢进的病人可出现
女患者,28岁,停经50天,恶心呕吐10天,加重3天,食入即吐,呕吐酸苦水,胸胁满闷,头晕头胀,烦渴口苦,舌淡红,苔薄黄,脉弦滑,查尿妊娠试验阳性,中医辨证为
甲在国内拥有房屋一套,但其本人一直在国外居住。甲的邻居乙将该房占为已有,并将之分割为前后两部分,前面临街的一部分用作门面房从事餐馆经营,后边一部分则用来出租。以下说法正确的是:()
资产评估最基本的方法是()。
阅读下列材料,回答有关问题。传统的作业模式强调对知识的巩固,使学生通过“题海”战术达到预期目的。传统的作业是专制的、封闭的、独立的,是反复僵化的思维训练,易造成学生思维的疲惫和对知识的麻木。新课标中有这样一段表述:“习题有助于巩固已学知识,提高运用知识的
派出机关是指由县级以上地方人民政府经有权机关批准,在特定行政区划内设立的行使相当于一级人民政府管理职权的行政机关。根据上述定义,下面哪项属于派出机关的范畴?()
若已经声明了函数"intfun(intx,inty=0);",则下列重载函数声明中,正确的是
Themostpopulargameintheworld.Peopleplayitinwater.
最新回复
(
0
)